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 ::
http://localhost:9090/scwcd/SampleJspView/SampleJspView? o/p :: is
Counter::
null
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
O/P::
counter::
ashok.markkandan@abcd.com html::
--------
SampleJspView .html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<FORM ACTION = "SampleJspView/SampleJspView" METHOD = "GET">
<INPUT TYPE = "SUBMIT"/>
</FORM>
</BODY>
</HTML>
Servlet::
-------------
SampleJspView .java
package SampleJspView;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SampleJspView extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException,ServletException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
RequestDispatcher rd = request.getRequestDispatcher("/JspCounter.jsp");
rd.forward(request,response);
}
}
jsp::
------
JspCounter.jsp
<html>
<body>
<H1>Counter::<H1>
<%!
String email;%>
<%! public void jspInit(){
ServletConfig sc = getServletConfig();
email = sc.getInitParameter("email");
ServletContext ctx = getServletContext();
ctx.setAttribute("mail",email);
}
%>
<%=email%>
</body>
</html>
web.xml
-------------
<servlet>
<servlet-name>SampleJspView</servlet-name>
<servlet-class>SampleJspView.SampleJspView</servlet-class>
</servlet>
<servlet>
<servlet-name>SampleJsp</servlet-name>
<jsp-file>
/JspCounter.jsp
</jsp-file>
<init-param>
<param-name>
email
</param-name>
<param-value>
ashok.markkandan@abcd.com </param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SampleJspView</servlet-name>
<url-pattern>/SampleJspView/SampleJspView</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SampleJsp</servlet-name>
<url-pattern>/SampleJsp</url-pattern>
</servlet-mapping>
Please advise me on this