The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Retriving Init Param of a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Retriving Init Param of a JSP " Watch "Retriving Init Param of a JSP " New topic

Retriving Init Param of a JSP

Ashok Markkanden

Joined: Oct 14, 2005
Posts: 3
I need a clarification in jsp .

I have set initparam to a jsp file . once a request is made from the html the request is sent to a Servlet from where i call the JSP using REQUESTDISPATCHER.
When i do so the page is dynamically loaded on the client side but i am unable to retrieve the parameter whihc was set in the web.xml for jsp.

the result page has the URL ::


o/p :: is



But When i access the URL

http://localhost:9090/scwcd/SampleJsp -------------> this is the URL pattern that i gave for JSP in servlet mapping

i can able to get the correct output


SampleJspView .html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE> New Document </TITLE>

<FORM ACTION = "SampleJspView/SampleJspView" METHOD = "GET">



SampleJspView .java

package SampleJspView;

import javax.servlet.*;
import javax.servlet.http.*;

public class SampleJspView extends HttpServlet

public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException,ServletException{

PrintWriter out = response.getWriter();

HttpSession session = request.getSession();
RequestDispatcher rd = request.getRequestDispatcher("/JspCounter.jsp");



<%! String email;%>
<%! public void jspInit(){
ServletConfig sc = getServletConfig();
email = sc.getInitParameter("email");

ServletContext ctx = getServletContext();








Please advise me on this
Gaurav Gambhir
Ranch Hand

Joined: Mar 04, 2006
Posts: 256
In the first case when you are getting Counter::null by accessing
container is looking for init-paramater for SampleJspView that are not
defined as a result you got null

But when you are accessing http://localhost:9090/scwcd/SampleJsp
whose corresponding JSP file is JspCounter.jsp
having init-parameter email, it gives the value for that

If you need result for the first case define parameters for that
Ashok Markkanden

Joined: Oct 14, 2005
Posts: 3
hey Gaurav,
Thanks for your reply.The solution that you gave was for setting init-param to a servlet and retrieve it through config object.
But the thing is i am going to add init-param only for a JSP, which should be retrieved when the Request is forwarded to a JSP.

I got the solution for it ..the jsp file name has to be given in the URL-PATTERN element in web.xml, so that the init param value set for a jsp can be retrieved in the same URL that servlet was called


I agree. Here's the link:
subject: Retriving Init Param of a JSP
It's not a secret anymore!