Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cant read config params in JSP

 
Mohit Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • 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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Ash More'
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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' ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic