my dog learned polymorphism*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HS&J - How to get JSP init parameters using EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HS&J - How to get JSP init parameters using EL" Watch "HS&J - How to get JSP init parameters using EL" New topic
Author

HS&J - How to get JSP init parameters using EL

Phoebe Jones
Greenhorn

Joined: Dec 15, 2004
Posts: 6
On page 208 of the book, we have an example of of setting up init param for JSP, and scriptlet code to get to it.

There is no EL implicit object for servlet/Jsp init params ( there is one for servletContext/applicatin init parameters. I know I can use the pageContext implite object to get to the servletConig object, eg.

${pageContext.servletConfig.servletName}

But I can't get to the initParameters . Please advise.

Thanks!
Phoebe Jones
Greenhorn

Joined: Dec 15, 2004
Posts: 6
I am sorry, it was pg 308.
Nitish Bahadur
Ranch Hand

Joined: Aug 25, 2003
Posts: 118
Servlet's init parameters are for Servlet, which are defined in web.xml. The same case is not true for JSP's, which, however, gets translated to Servlets too.

Please refer to HFS authors response on Pg 155 of HFS.
Phoebe Jones
Greenhorn

Joined: Dec 15, 2004
Posts: 6
Nitish,

If you read pg. 308, you'd see what I am asking about. I can get the init params, but I am trying to do it without the scriptless way, i.e. using EL.

Thanks for your reply!
Gabriel Forro
Ranch Hand

Joined: Apr 16, 2004
Posts: 59
Hi,

I think, that there is no built-in way to access the servlet init parameters through EL.
If You do not want to use scripting:
1. You can create an EL function, which takes the ServletConfig object and the name of the init parameter as a String object and returns the value of the init parameter.
2. You can create a custom tag


Gabriel
Phoebe Jones
Greenhorn

Joined: Dec 15, 2004
Posts: 6
Thanks. Good to know that there might not be other ways than to write an EL function or a custom tag.

I tried it with an EL function . It works quite nicely.
The function signature is java.util.Map jspInitParams( javax.servlet.ServletConfig )

and I call it with, eg. ${ myFunc:jspInitParams( pageContext.servletConfig) }

or
${ myFunc:jspInitParams( pageContext.servletConfig)["initParamName"] }
 
Don't get me started about those stupid light bulbs.
 
subject: HS&J - How to get JSP init parameters using EL
 
Similar Threads
EL and jsp:usebean..type/class
How do we get Servlet Init Parameter thru EL?
init parameters for jsp
A question about servlet initParameter
question on implicit objects in EL?