• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP - Problem in reading InitParameter

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I trying to read the config parameter for the JSP page; but I am getting value as "null". I do not know why it is not retrieving the param-name "name".
Please help on this

web.xml
-------

<servlet>
<servlet-name>AppView</servlet-name>
<jsp-file>/AppView.jsp</jsp-file>
<init-param>
<param-name>name</param-name>
<param-value>raj</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>AppView</servlet-name>
<url-pattern>/AppView.jsp</url-pattern>
</servlet-mapping>


AppView.jsp
-----------
..
<%! //Init Params
ServletConfig config = null;
String name;
public void jspInit()
{
try{
config = getServletConfig();
name = config.getInitParameter("name");
System.out.println(" Name "+name);
}

}
%>
..


thanks in advance.

 
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

Don't use declaration tag fro defining method.
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi,

May be this will help you...

http://nishanpatel.wordpress.com/2009/04/30/deploymentdescriptor/

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
config is an implicity variable on jsp. and change your url-pattern name in your web.xml and trigger using it.

Hope this helps
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you posted whole code?
where is catch block?



I just commented try and tried your code it is working fine.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and please use code tag to post your code. so that we can read your code clearly
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Welcome to javaranch. We are happy to have you Here
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic