• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Unable to fetch config parameter in jsp

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am trying to fetch the configuration parameter from withing jspInit() method which i have overridden in my jsp code, although i am able to retrieve the context parameter.

web.xml
--------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>name</param-name>
<param-value>Rahul</param-value>
</context-param>
<servlet>
<servlet-name>Counter</servlet-name>
<jsp-file>/Counter.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>chetan.dhewal@gmail.com</param-value>
</init-param>
</servlet>
<display-name>web3</display-name>
<welcome-file-list>
<welcome-file>Counter.jsp</welcome-file>
</welcome-file-list>
</web-app>

--------------------------

JSP code
-----------------------------
<html>
<body>
<%! public void jspInit()
{
ServletConfig cfg = getServletConfig();

String id = cfg.getInitParameter("email");

ServletContext ctx = getServletContext();

String name = ctx.getInitParameter("name");

System.out.print(id +" "+name);
}
%>
<%! int counter = 0; %>
<%! int countermethod()
{
counter += counter + 2;

return counter;
}

%>
<%= countermethod() %>
</body>
</html>
-----------------------------

I think there is some servlet naming problem , but I am not able to pin point the problem. Is it not possible to get it or this is not the correct way of fetching cofig parameters.

With Regads
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you just need to write a <servlet-mapping>. without <servlet-mapping> you are accessing your jsp as jsp, not as servlet. just add this to your web.xml and you are all good.


[ September 09, 2008: Message edited by: Ashish Gauswami ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic