Hi all,
I am facing a critical problem for session tracking. The code is working fine using resin.
but using
tomcat 3.3.1, it is not working.
let me explain the scenario.
I have a html file which calls the
servlet, and after processing, the servlet redirects the response to a
jsp file using sendRedirect() method.
When i retreive the session value using session.getAttribute("xVar") in the jsp, it gives null.
then, i used getServletContext().getRequestDispatcher("url").forward(request,response) in the servlet class instead of sendRedirect(), it gives appropriate value in the jsp.. but, it will not work for other pages(entire session)..
from this i have confirmed that, session variable setting is working..
I tested the same code with IE5.5 and Netscape 4.7, it gives the same error.
I also compared resin.conf file with server.xml,in resin they used enable cookies and URL-Rewriting.
Is there any settings to be done in server.xml to get session variables..
Can anyone please ,help me to resolve this issue..
let me paste the code here..
Thanks in advance..
bye,
Murugan
<html>
<head><title>This is the html file</title></head>
<body>
<form action="/servlet/SampleServlet" method=GET >
<a href="http://localhost:8080/servlet/SampleServlet" > Click to Servlet </a>
</form>
</body>
</html>
----------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SampleServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
HttpSession session = null;
res.setContentType("text/html");
session = req.getSession(true);
session.setAttribute("xSample","This is a sample string");
if (session.getAttribute("xSample") != null){
res.sendRedirect("/NetCAST/Home/NC_Sample.jsp");
}
String sSample = (String) session.getAttribute("xSample");
System.out.println(sSample);
}
}
-----
Web.xml
------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>
SampleServlet
</servlet-name>
<servlet-class>
SampleServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
SampleServlet
</servlet-name>
<url-pattern>
/servlet
</url-pattern>
</servlet-mapping>
</web-app>
--------
NC_Sample.jsp
------------
<html>
<head><title>Sample JSP [age </title></head>
<body>
<%
if (session.getAttribute("xSample")!= null){
String strSample= (String)session.getAttribute("xSample");
out.println("Sample got : "+strSample);
System.out.println(strSample);
}else
System.out.println("String is null");
%>
</html>
The cookies enable attributes in Resin which is not specified in tomcat is
<session-config>
<session-max>4096</session-max>
<session-timeout>30</session-timeout>
<enable-cookies>true</enable-cookies>
<enable-url-rewriting>true</enable-url-rewriting>
</session-config>