aspose file tools*
The moose likes JSP and the fly likes problem with accessing JSP init parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "problem with accessing JSP init parameters" Watch "problem with accessing JSP init parameters" New topic
Author

problem with accessing JSP init parameters

sandeep raj
Greenhorn

Joined: Mar 06, 2009
Posts: 10
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: 2902
    
    1

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
thanks subhash.. it worked.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

sandeep raj wrote:.. it worked.

Now, Remove that JSP page and make servlet of it, because that's good practice
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with accessing JSP init parameters