我认为你不能直接这样做,你可以通过这个代码
${pageScope}<br> ${requestScope}<br> ${sessionScope} <br> ${applicationScope}
或更详细的
<%
Enumeration attrNames=request.getServletContext().getAttributeNames();
while(attrNames.hasMoreElements()){
String ctxAttribute=(String) attrNames.nextElement();
out.print("<br> Attribute Name --> "+ctxAttribute+", has value Value --> "+request.getServletContext().getAttribute(ctxAttribute));
}
out.println("<br><br>");
attrNames=application.getAttributeNames();
while(attrNames.hasMoreElements()){
String ctxAttribute=(String) attrNames.nextElement();
out.println("<BR> Attribute Name --> "+ctxAttribute+", has value Value --> "+application.getAttribute(ctxAttribute));
}
%>
转储应用范围的所有属性。如果你想获得这个参数,一种方法,当上下文初始化时,可以将此属性应用于应用范围:
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyContextListener implements ServletContextListener {
private static final Log logger = LogFactory.getLog(MyContextListener.class);
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
String email= servletContextEvent.getServletContext().getInitParameter("email");
logger.info("Use email:" + email);
servletContextEvent.getServletContext().setAttribute("email", email+"==setbylistener");
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}
,不要忘记配置它在你的web.xml
<context-param>
<param-name>email</param-name>
<param-value>test123</param-value>
</context-param>
<listener>
<listener-class>MyContextListener</listener-class>
</listener>
希望这会有所帮助。