Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use EL to access servlet init in web.xml

 
Brenda Kwok
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to use use EL to access admin eamil

<servlet>
<init-param>
<param-name>adminemail</param-name>
<param-value>abc@hotmail.com</param-value>
</init-param>
</servlet>
 
Wasim Ayoubi
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brenda

I did not find any direct way to access the Servlet Init Param from EL but you can still do it using EL functions you can do this --->

---------------------------------------------------------------
Create a class and define the following function

package whatever;
public class ELFunctions {
public static String getInitParam(PageContext pageContext, String key){
return pageContext.getServletConfig().getInitParameter(key);
}
}
---------------------------------------------------------------
define a whatever.tld file, it should look like this

<uri>http://www.wia.com/el/functions</uri>
<function>
<name>getInitParameter</name>
<function-class>whatever.ELFunctions</function-class>
<function-signature>java.lang.String getInitParam(javax.servlet.jsp.PageContext, java.lang.String)</function-signature>
</function>
---------------------------------------------------------------
in your jsp file
<%@taglib uri="http://www.wia.com/el/functions" prefix="wia"%>

<h2>${wia:getInitParameter(pageContext,"adminemail")}</h2>

--------------------------------------------------------------
your dd file looks like this
<servlet>
<init-param>
<param-name>adminemail</param-name>
<param-value>abc@hotmail.com</param-value>
</init-param>
</servlet>

try it and I think everything will be fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic