The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP config Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP config" Watch "JSP config" New topic

JSP config

Martyn Clark
Ranch Hand

Joined: Apr 16, 2005
Posts: 108
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

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...<br /> <br />SCJP 1.4 SCWCD 1.4
Martyn Clark
Ranch Hand

Joined: Apr 16, 2005
Posts: 108
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.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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.

[My Blog]
All roads lead to JavaRanch
Martyn Clark
Ranch Hand

Joined: Apr 16, 2005
Posts: 108
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.
I agree. Here's the link:
subject: JSP config
It's not a secret anymore!