Tur*_*_07 8 java jsp el spring-mvc
如何从JSP页面上的ServletContext对象中找到我的属性?
我之前设置它:
public class MyServletContextListener implements ServletContextListener{
private static final Logger logger = LoggerFactory.getLogger(MyServletContextListener.class);
@Override
public void contextInitialized(ServletContextEvent event) {
logger.info("Init gameEngine in listener");
Engine engine = Engine.getInstance();
event.getServletContext().setAttribute("engine", engine);
}
@Override
public void contextDestroyed(ServletContextEvent event) {
}}
Run Code Online (Sandbox Code Playgroud)
现在想进入JSP页面.也许有可能${pageContext.servletContext.attributeNames}吗?
Nir*_*ati 17
使用jstl可以直接在jsp中获取应用程序对象
${applicationScope['attributeNames']}
Run Code Online (Sandbox Code Playgroud)
通过使用此表达式,您可以直接在jsp中获取应用程序级别对象
要么
使用scriptlet也可以在jsp中获取应用程序对象,如果你在web_app 3.0版上运行并且有Servlet 3.0 API,你可以直接从HttpServletRequest获取ServletContext对象,如下例所示:
<%
ServletContext sc = request.getServletContext();
sc.getAttribute("attributeName");
%>
Run Code Online (Sandbox Code Playgroud)
但是当你使用scriptlet来获取应用程序对象时,你必须强制转换应用程序对象,因此
JSTL使用scriptlet代码要好得多
| 归档时间: |
|
| 查看次数: |
26975 次 |
| 最近记录: |