且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java(JSP/Servlet):等效于.jsp内部的getServletContext()

更新时间:2023-12-04 18:20:11

可通过application隐式对象访问ServletContext.

由于每个JSP都是servlet,因此您也可以使用getServletContext().

Since each JSP is a servlet, you can also use getServletContext().

但是..避免在JSP中使用类似的代码.取而代之的是,在Servlet中获取所需的值并将其设置为request属性,只需在JSP中读取即可(***通过JSTL)

But.. avoid having code like that in the JSP. Instead, obtain the value you need in your servlet and set it as a request attribute, simply reading it in the JSP (via JSTL preferably)