permaculture playing cards*
The moose likes JSP and the fly likes Accessing servlet-config parameter through EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Accessing servlet-config parameter through EL" Watch "Accessing servlet-config parameter through EL" New topic
Author

Accessing servlet-config parameter through EL

Sudhakar Sharma
Ranch Hand

Joined: Apr 04, 2009
Posts: 71

Hi Everybody,

How would i get servlet-config parameters in a jsp through EL???
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066



Won't this work?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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

Joined: Nov 04, 2009
Posts: 2066

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?
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

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


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Thanks Hebert Coelho for the link!
Sudhakar Sharma
Ranch Hand

Joined: Apr 04, 2009
Posts: 71




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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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

Joined: Apr 04, 2009
Posts: 71

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Sigh. How?
Ye Mingjian
Greenhorn

Joined: Jul 14, 2010
Posts: 5
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

Joined: Nov 04, 2009
Posts: 2066

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

Joined: Apr 04, 2009
Posts: 71

that's right and i stuck to old lagacy code.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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

Joined: Apr 04, 2009
Posts: 71

I got the point.

Thank You
Soniya Ahuja
Ranch Hand

Joined: Jul 20, 2008
Posts: 83
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.


SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing servlet-config parameter through EL