• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about servlet initParameter

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone know how to use EL to get the servlet initParameter? Thanks.
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to read some EL primer documents. I believe there are some links off the ranch page.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I propose you three questions:
1) What servlet want you get the init parameters of?
2) Can you get those servlet init parameters not using EL?
3) Can a JSP page have servlet init parameters?

Hope this helps.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) What servlet want you get the init parameters of?
jsp servlet( that's the jsp translated into servlet by container)
2) Can you get those servlet init parameters not using EL?
since jsp is translated into servlet...
3) Can a JSP page have servlet init parameters?
yes you can pass init parameter to JSP ( servlet) by using
<servlet-name>name</servlet-name> <jsp-file>/a.jsp</jsp-file>

regarding getting init parameters of servlet from JSP using EL..
we cannot get directly using EL as no implicit object is defined for getting servlet init parameters
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that this works:

${pageContext.config.initParameter['paramName']}

[ March 22, 2005: Message edited by: Jean Meira ]
[ March 22, 2005: Message edited by: Jean Meira ]
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Praveen Kumar Mathaley:
1) What servlet want you get the init parameters of?
jsp servlet( that's the jsp translated into servlet by container)


Sure, if it is possible, this has to be the servlet.


2) Can you get those servlet init parameters not using EL?
since jsp is translated into servlet...)


Try to do it. If you can, please, tell me how you did it.


3) Can a JSP page have servlet init parameters?
yes you can pass init parameter to JSP ( servlet) by using
<servlet-name>name</servlet-name> <jsp-file>/a.jsp</jsp-file> )


OK, the servlet generated from the JSP could have init parameters, but the question is: Can you get them?
Please, don't be theoric in your answers. I wrote code to get the init parameters and it was no possible. Here's the code:
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jean Meira:
I believe that this works:

${pageContext.config.initParameter['paramName']}



Nope, it can't work since it isn't even correct syntactically. There's no such thing as a getConfig() bean style method in pageContext.

It would be syntactically correct to write ${pageContext.servletConfig} (since there's a getServletConfig() method in pageContext), but you can't do anything else.

In fact, I'm pretty sure that you can't get the init parameters even if you don't use EL.
 
ZHAN QING LUO
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, every one, Thanks very much for your responses and discussion. I'm preparing for the SCWCD exam. I know it's very easy to use script to get servlet init Parameter.like this:

<%= config.getInitParameter("name")%>

but I'm just curious that if we can use EL to do the same thing. I know this works: ${pageContext.servletConfig.initParameterNames}

but this one don't work: ${pageContext.servletConfig.initParameter['name']}
for example 'name' is the parameter

so, what's the next... Is EL can't do this???
[ March 22, 2005: Message edited by: ZHAN QING LUO ]
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ZHAN QING LUO:
I know it's very easy to use script to get servlet init Parameter.like this:

<%= config.getInitParameter("name")%>


It's obvious that this works in a servlet but, what about a JSP page? Try to do it, and tell me if it works for you. It doesn't work for me.


I know this works: ${pageContext.servletConfig.initParameterNames}


Really? Have you tried to do it? I did it and it doesn't work.

Has anybody REALLY tried to set and then get an init parameter in a JSP page?
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I am pretty sure you can get both context and servlet init paramters with JSP.

Here is how I did it:

1) You have to bind init parameters for JSP in DD:


2) Use this scriptlet in JSP to access defined init parameters:

(You can also use pageContext object for above code)

3) You can even do this !


So it is pretty clear now. You can access init parameters any way round, either by config or by pageContext object. Same holds true for context init parameters.

However, when using EL, you cannot access init parameters. Although init paramter names can be retrieved using EL:

Yes, you can only get that far, and yes for both config and application objects.

I hope its clear now.
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bassam

Everything is clear now. I was missing the <servlet-mapping> in the DD and that's why I couldn't get the servlet init parameters in the JSP page.

Cheers,
Jose
 
Praveen Kumar Mathaley
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
at last reached conclusion of what i have said...
thank you bassam...
 
Bassam Zahid
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everybody is welcome.
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody figure out why people who designed the EL gave us objects to easily get attributes in any scope, request parameters, request headers, cookies and context init parameters, but they made the EL in a way that it is impossible to get servlet init parameters?

Any suggestions are welcome.
[ March 30, 2005: Message edited by: Jose Esteban ]
 
Bassam Zahid
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think support for init parameters will be added in future EL versions through JCP.
 
expectation is the root of all heartache - shakespeare. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic