• 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

Cant read config params in JSP

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In HFSJ page# 308, it says init params can be read in a jsp by using <jsp-file> tag as follows -

<servlet>
<servlet-name>ServTest</servlet-name>
<jsp-file>/index.jsp</jsp-file>
<init-param>
<param-name>level</param-name>
<param-value>10th</param-value>
</init-param>
</servlet>
index.jsp code -
<%= config.getInitParameter("level") %>

But it prints "null". I cant understand why JSP cant read the init param. Please help me understand where I am going wrong.

Question2 -
I put both <jsp-file> and <servlet-class> tags in <servlet> (using Eclipse IDE)and it gives error, its ok if I have only one of them present. Can't we put both of them together in <servlet> tag?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which mapping did you assign to the ServTest servlet ? You have to go through the mapping, not access the jsp file directly.

I put both <jsp-file> and <servlet-class> tags in <servlet> (using Eclipse IDE)and it gives error, its ok if I have only one of them present. Can't we put both of them together in <servlet> tag?


No you can't, that would not make sense. A servlet is either represented by a class file, or by a JSP file, not both at the same time.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add a <servlet-mapping> element to web.xml as:



Just add this mapping, you will be able to the servlet init paramter
[ April 22, 2008: Message edited by: Ash More' ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic