Author
problem with accessing JSP init parameters
sandeep raj
Greenhorn
Joined: Mar 06, 2009
Posts: 10
posted Mar 06, 2009 18:37:40
0
I am using eclipse for my project development. I basically created a web.xml file in the WEB_INF folder and added the following within the webapp tags
<servlet >
<servlet-name>MyTestInit</servlet-name>
<jsp-file>/BasicCounter.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>kick@wicked.com</param-value>
</init-param>
</servlet>
<context-param>
<param-name>email</param-name>
<param-value>test@test.com</param-value>
</context-param>
I also made a jsp file BasicCounter.jsp in the context root and tried to access the servlet init parameter using
<% String email = config.getInitParameter("email");
out.println("Email id is :" +email+"<br>");
%>
but all it returned is Null;
I was however able to access the context init parameter in the same jsp file using the following
<% String email1 = application.getInitParameter("email");
out.println("Email id is :" +email1+"<br>");
%>
and get the output test@test.com
Am I doing anything wrong while trying to access the servlet init parameters?
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
sandeep raj wrote: I am using eclipse for my project development. I basically created a web.xml file in the WEB_INF folder and added the following within the webapp tags
<servlet>
<servlet-name>MyTestInit</servlet-name>
<jsp-file>/BasicCounter.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>kick@wicked.com</param-value>
</init-param>
</servlet>
<context-param>
<param-name>email</param-name>
<param-value>test@test.com</param-value>
</context-param>
I also made a jsp file BasicCounter.jsp in the context root and tried to access the servlet init parameter using
<% String email = config.getInitParameter("email");
out.println("Email id is :" +email+"<br>");
%>
but all it returned is Null;
Why don't use made a servlet and and map it to "MyTestInit", In that servlet class, check whether init param are coming or not !
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
subhash uppalapati
Greenhorn
Joined: Nov 03, 2005
Posts: 17
Please refer to the the topic http://www.coderanch.com/t/290712/JSP/java/JSP-Initialization-Parameters
sandeep raj
Greenhorn
Joined: Mar 06, 2009
Posts: 10
posted Mar 07, 2009 00:02:00
0
thanks subhash.. it worked.
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
sandeep raj wrote: .. it worked.
Now, Remove that JSP page and make servlet of it, because that's good practice
subject: problem with accessing JSP init parameters