Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing servlet-config parameter through EL

 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

How would i get servlet-config parameters in a jsp through EL???
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Won't this work?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • 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?
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator



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
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sigh. How?
 
Ye Mingjian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
that's right and i stuck to old lagacy code.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I got the point.

Thank You
 
Soniya Ahuja
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic