I am trying to print the value of Servlet initParameter in EL. I configured name parameter in wb.xml. I used PageContext to get the value of name parameter. But I get ServletException.
javax.servlet.ServletException: Unable to find a value for "initparameter" in object of class "org.apache.catalina.core.ApplicationHttpRequest" using operator "."
Ben you misunderstood the question. I am trying to print the value of Servlet initParameter in EL For context int param I would have used the EL implicit object initParam.
When we can use ${pageContext.request.method} to know the request method name then I think the following syntax is correct for getting the servlet init parameter
But that would only allow access to init parameters declared for this JSP's generated servlet; not the controller's.
I think what you would need to do is either declare the init-parameter as a context init param (in which case you would retrieve it from the context implicit object variable) or create a servlet entry for your JSP so that you have access to servlet init params declared in web.xml.
Posted by Ben But that would only allow access to init parameters declared for this JSP's generated servlet;
I think this is correct to get the JSP's generated servlet init parameters.
${pageContext.config.initParameter.name}
But I am getting exception as
javax.servlet.ServletException: Unable to find a value for "config" in object of class "org.apache.jasper.runtime.PageContextImpl" using operator "."
Note: The request is forwared from a servlet to jsp. I also have configuration for the servlet in web.xml. Hope the sequence I am following is not wrong
Originally posted by vishnu prakash: Originally Posted by Ben What does this mean. How to do this? Kindly explain in detail
I just tried myself and was unable to get a servlet init param using EL. It may be possible but I haven't found it yet.
However, in the JSP spec, I did see a way to read context init params with el. This might serve your purpose.
EL:
web.xml
Again, it may still be possible to get a servlet init-param with EL. Look through the JSP spec (link in my signature).
To create a servlet entry for a jsp, create a regular <servlet> entry but use <jsp-file>/pageName.jsp</jsp-file> instead of a <servlet-class> entry. From there it's the same as any other servlet entry, add your init-params, mappings, ect.. the same way you would for any other servlet.
To create a servlet entry for a jsp, create a regular <servlet> entry but use <jsp-file>/pageName.jsp</jsp-file> instead of a <servlet-class> entry. From there it's the same as any other servlet entry, add your init-params, mappings, ect.. the same way you would for any other servlet.
I have already done that and posted in my previous post. Even that doesn't work.
Regarding context init params, things are clearly explained in HFSJ book. The problem is I couldn't find a way to access servlet init parameter as well as JSP's generated servlet init parameters in my JSP page.
I wish Bear Bibeault takes a look at this thread and provides a solution.
pre-supposes that the request has some means of returning init params, and it does not. Init params are only available from the servletConfig of an individual servlet which is orthogonal to the requests.
The EL has a handful of implicit variables defined, but nothing to obtain the init params for individual servlets (or JSP-generated servlets). If you were to attempt to set something like that up, which servlet would this obtain the params for? The request can be passed around multiple resources, both servlets and JSPs.
Even if the request had a method such as getInitParam(), you wouldn't be able to use it since you would need to pass the name of the param you are trying to obtain to the method. And the EL has no means to do that.
Implicit EL variables such as paramValues work the way they do because they are not methods, but rather Map instances.
My suggestion, if you want access to the initParams for the controller servlet, is to create a Map of the init params for the servlet and place it on the request as a scoped variable -- let's say named initParameters. You would then be able to obtain any param by name with ${requestScope.initParameters.name}. [ October 05, 2005: Message edited by: Bear Bibeault ]
Post by:autobot
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
a bit of art, as a gift, the permaculture playing cards