/ Published in: Java
Rather than hard-coding values shared between classes/methods/servlets, it's good to use content params in web.xml.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!-- add context params in your web.xml --> <web-app ...> <context-param> <param-name>ROLE-ADMIN</param-name> </param-value>admin</param-value> </context-param> </web-app> USAGE: <!-- method usage --> public void someMethod(ServletConfig config) { ServletContext application = config.getServletContext(); } <!-- jsp scriplet usage--> if (userRole.equals(application.getInitParameter("ROLE-ADMIN"))) { //do something } <!-- EL usage --> <c:if test="${userRole eq initParam.ROLE-ADMIN}"> do something </c:if>
URL: http://www.coderanch.com/t/287799/JSP/java/JSP-Java-class-s-static