This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with accessing JSP init parameters

 
sandeep raj
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
subhash uppalapati
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please refer to the the topic http://www.coderanch.com/t/290712/JSP/java/JSP-Initialization-Parameters
 
sandeep raj
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks subhash.. it worked.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandeep raj wrote:.. it worked.

Now, Remove that JSP page and make servlet of it, because that's good practice
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic