aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question about servletConfig() and servetContext() in JSP in HF BOOK 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 "Question about servletConfig() and servetContext() in JSP in HF BOOK" Watch "Question about servletConfig() and servetContext() in JSP in HF BOOK" New topic
Author

Question about servletConfig() and servetContext() in JSP in HF BOOK

A Phatak
Greenhorn

Joined: Sep 22, 2011
Posts: 24
I am studying from the K&B Head first book for this exam. I am also fairly new to JSPs.
K&B book very conveniently skips from initParameter("...") to get/set Attributes in application scopes.

Take a look at page 310 bottom part of the page, where she uses getServletConfig().getInitParameter("email") and stuffs it as an attribute value into servletContext.

Am I missing something? Are we not supposed to access getServletContext().getInitParameter() in a JSP. The reason I am asking is there is no mention of this in the EL section either.
The attribs are directly being accessed as ${application.attrib_name} but no initParameters ever get access this way (or even within <%= %>


I can understand this kind of an approach in an MVC scenario, perhaps the servletConfig param value will not be available in a view_jsp after it got forwarded to from a servlet. So a servlet might have to stuff it as a request/context attribute. But....??

Thanks for the answer


ocpjp 6 (86%)
Sharad Kharya
Ranch Hand

Joined: Oct 15, 2008
Posts: 68
First thing i am not sure whether you are referring to the correct page number (310). I ma referring HFSJ 1st edition and didn't find such example.

You can use to retrieve context init parameters in JSP.

application is an implicit ServletContext Object available in JSP. with this you didn't need to write all above code to get context init parameters.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1695
    
  25

Take a look at page 310 bottom part of the page, where she uses getServletConfig().getInitParameter("email") and stuffs it as an attribute value into servletContext.
Am I missing something?

Nope, you have seen it correctly. You can't get to the Servlet init parameters in a JSP via EL (and we are not suppose to retrieve them via a scriptlet). Many people have wondered why, but so far I haven't really read anything explaining why. The specifications also do not mention anything about it. So why it is left out is also not explained: maybe it was forgotten, maybe it was on purpose: we don't know.

On Javaranch we have a faq-item about it

Regards,
Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about servletConfig() and servetContext() in JSP in HF BOOK