I think it's not possible to read the init-param of a servlet in a jsp page. The config object refers to the ServletConfig of the Jsp not the servlet you are intended to read from. I did some search on the API to see if we have retrieve the ServletConfig of a particular servlet and came up with empty.
If you want to share the params between JSP and servlet you should consider using context-params.
though i've specified the jsp file name in servlet description i cudn't get the servlet init parameters.
This is my servlet snippet System.out.println(" Servlet init paramater =>"+getServletConfig().getInitParameter("PrimeMinister")); RequestDispatcher dispatch = req.getRequestDispatcher("third.jsp"); dispatch.forward(req,res);
Maybe you don't want to access init params from the JSP, you seem to be confusing the concept.
You could remove the jsp-file line from your web.xml, and in TestJspServlet.java :
And get it back from JSP, from the request.
Joined: Mar 13, 2006
i am really confused now.what is the use of <jsp-file> tag in <servlet> tag. If we can't access the servlet's init parameters inside a jsp,is that for accessing the jsp init parameters. And i've read in HFSJ that inside the jspInit() we have access to ServletConfig() and ServletContext().If that is the case i should be able to access the init parameters within the jspInit(),right.
Well as I understand from the reply from Satou kurinosuke U CAN access the init parameters from a JSP by using the code he has given, but the recommended way is to access the init parameters from a servlet and pass them to the JSP as request attributes !
SCJP 1.4 (90%)<br />SCWCD 1.4 (88%)
Joined: Mar 13, 2006
Well, Earlier i've misunderstood servlet init parameters with jsp init parameters.Now tell me what would the config.getInitParameter() inside a jsp return.Ideally it has to be the init parameters which i've set in the DD
<servlet> <servlet-name>JspServlet</servlet-name> <jsp-file>/third.jsp</jsp-file> <init-param> <param-name>skipper</param-name> <param-value>Ponting</param-value> </init-param> </servlet> [For your information i'm directly accessing the jsp now] Still i'm getting the null from config object.
For your information i'm directly accessing the jsp now
This is the problem. The container does not map a jsp file to init parameters. It maps servlets to their init parameters. So you have to access your jsp file via a url, which is mapped to it. Try to add: <servlet-mapping> <servlet-name>JspServlet</servlet-name> <url-pattern>/third</url-pattern> </servlet-mapping>