Return to Snippet

Revision: 16051
at July 24, 2009 10:37 by sunkist


Updated Code
<!-- 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();
     String adminRole = application.getInitParameter("ROLE-ADMIN");
	  
}


<!-- 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>

Revision: 16050
at July 24, 2009 10:37 by sunkist


Updated Code
<!-- 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();
     String userRole = application.getInitParameter("ROLE-ADMIN");
	  
}


<!-- 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>

Revision: 16049
at July 24, 2009 10:33 by sunkist


Initial Code
<!-- add context params in your web.xml -->
<web-app ...>
    <context-param>
        <param-name>XXX_ROLE_ADM_ID</param-name>
        </param-value>Hello</param-value>
    </context-param>
    <context-param>
        <param-name>XXX_ROLE_PMCRPT_ID</param-name>
        </param-value>World</param-value>
    </context-param>
</web-app>


USAGE:



<!-- method usage -->

public void someMethod(ServletConfig config) {
 
     ServletContext application = config.getServletContext();
     String foo = application.getInitParameter("foo");
	  
}


<!-- jsp scriplet usage-->

if (adminUserName.equals(application.getInitParameter("ROLE-ADMIN"))) 
{
   //do something
}

<!-- EL usage -->

<c:if test="${adminUserName eq initParam.XXX_ROLE_ADM_ID}">
   do something
</c:if>

Initial URL
http://www.coderanch.com/t/287799/JSP/java/JSP-Java-class-s-static

Initial Description
Rather than hard-coding values shared between classes/methods/servlets, it's good to use content params in web.xml.

Initial Title
using context init parameters in web.xml

Initial Tags
java

Initial Language
Java