• 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

Accessing servlet-config parameter through EL

 
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everybody,

How would i get servlet-config parameters in a jsp through EL???
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Won't this work?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abimaran Kugathasan wrote:Won't this work?


Only for people following poor practices and putting Java code in JSPs.

And, the poster specifically asked about using the EL, so no, it won't work to answer the question.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sudhakar Sharma wrote:How would i get servlet-config parameters in a jsp through EL?



For which servlet? As a JSP can be forwarded to by any number of controller servlets, it's not clear what you are trying to accomplish. Please elaborate.

P.S. Please end questions with a single question mark.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, sorry, I don't concentrate there! And pageContext is a JavaBean, so, it'll follow Bean naming rules. Can't we access on that way?
 
Ranch Hand
Posts: 754
Eclipse IDE Java
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Hebert Coelho for the link!
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hebert Coelho wrote:Take a look here! http://faq.javaranch.com/java/InitParamsThruExpressionLanguage




Hi Hebert,

Thanks for the link, it means we cannot able to use EL in that way as in getting request's method like

${pageContext.request.method}

then how can i access that, initParam is built for the context, is there anything to the rescue?

Here is the detailed question

I 'm using a.jsp in my app and sets it's <init-param> in <servlet> in the DD, now i wanted to access this param-value in a.jsp using EL
is it possible or not ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You still haven't answered my question. Are you talking about context parameters, or a particular servlet's init parameter? If the later, what is the relationship between the servlet and the JSP?
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You still haven't answered my question. Are you talking about context parameters, or a particular servlet's init parameter? If the later, what is the relationship between the servlet and the JSP?



I am configuring the a.jsp file in DD with <init-param> now is there any way to access this init parameter in a.jsp through EL
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sigh. How?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sudhakar Sharma wrote:

Bear Bibeault wrote:You still haven't answered my question. Are you talking about context parameters, or a particular servlet's init parameter? If the later, what is the relationship between the servlet and the JSP?



I am configuring the a.jsp file in DD with <init-param> now is there any way to access this init parameter in a.jsp through EL


Bear Bibeault is asking that you are using
<context-param>
<param-name>context</param-name>
<param-value>yes</param-value>
</context-param>

or
<servlet>
<init-param>
<param-name>context</param-name>
<param-value>yes</param-value>
</init-param>
</servlet>
it's the same for the <param-name>,<param-value>.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, he asked about the JSP initialization parameters declared in web.xml. Since we need pass the parameter's literal name to the method, we can't use El. Please confirm!

Thanks!
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's right and i stuck to old lagacy code.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would venture that if you need to do this, you are likely violating proper Separation of Concerns in your JSP. It's much more likely that good practices would have you associating the init parameters with the servlet controller for the JSP.
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the point.

Thank You
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A cheap work around would be use a tld file that maps getInitParameterName of ServletConfig as an el function. Then you can include that TLD in your jsp and invoke the function using EL and also pass it the param name. However, as suggested by Bear, the parameters could rather be set as attributes on may be the request scope in the controller servlet which calls the jsp page.
reply
    Bookmark Topic Watch Topic
  • New Topic