Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

problem with accessing JSP init parameters

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer to the the topic https://coderanch.com/t/290712/JSP/java/JSP-Initialization-Parameters
 
sandeep raj
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks subhash.. it worked.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic