• 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 config

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I am having a problem retrieving init parameters set in the DD, In HFSJ it say you can set initialization parameters more or less the same way as you would a normal servlet.

This is i have set in the DD
<servlet>
<servlet-name>TestInit</servlet-name>
<jsp-file>/Test.jsp</jsp-file>
<init-param>
<param-name>support</param-name>
<param-value>support@somewhere.com</param-value>
</init-param>
</servlet>

and in the jsp i call with this: <%= config.getInitParameter("support") %>

All i get back is null, so this says the parameter does not exist.
is there something i have no done correctly in the dd?
any help would be much appreciated.
 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I think i have sorted the problem i was having. If the page is accessed directly using the full url i.e. http://localhost:8080/HFSJ/TestInit.jsp

The cofiguration will not be used, because the jsp engine creates two different instances of the generated servlet class. One for accessing it's named servlet and one for accessing it as a jsp page meaning both these get a different ServletConfig object. if you are directly accessing it using the url above you must also configure servlet-mapping elements in the DD. This will ensure the container will generate only one instance.

If any one can shed a bit more light on why would the container create 2 instances without the servlet-mapping element i would be grateful.
 
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
I think that you're misunderstanding the use of <servlet> and <servlet-mapping> tags. Your <servlet> tag is ok, please show us the corresponding <servlet-mapping> tag. Without it, there's no way to access the servlet.

There are not two instances of the same jsp. There are two ways of accessing it. Straight away via its url, or implicitly via its servlet mapping.
 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satou
thanks for your reply, The way i am understanding this is: if i configure in the DD as i have done in the previous post if you use the url http://localhost:8080/webapp/servlet/TestInit.jsp it all works fine and i get back the init parameters in the jsp, Without having any servlet mapping in the DD for that jsp page. But if i use the the actual url with out the use of servlet invoker then the jsp is returned with value of null for the init param values. But if i then set in the DD servlet-mapping element for the jsp page then i can access the page with default url and it all works fine and i get back the init parameter values ok in the page. I have tried these and this is how it seems to work in Tomcat anyway.

I soppose my question is that if i change the url in the <jsp-file> element i get 404 file not found which is what i would expect. What i am wondering is if this gets read from the DD then why are the init paramters not getting initialized at the same time.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic