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>email@example.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.
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.
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.
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.