File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Phoebe Jones
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, it was pg 308.
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Phoebe Jones
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"] }
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic