• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry, it was pg 308.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"] }
 
reply
    Bookmark Topic Watch Topic
  • New Topic