You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Andrew Shiels <sh...@ssi-schaefer-noell.com> on 2000/07/14 12:14:20 UTC
My parameters are lost when storing them in HttpSession using Servlet
Tomcat version: 3.1
O/S: WinNT 4.0 SP6
JDK: Java(TM) 2 SDK, Standard Edition Version 1.3.0
I have a servlet which verifies user login information in a database. If the user is allowed to login I add some information to the session object and redirect the user to a start page:
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
..
..
HttpSession session = req.getSession(true);
session.setAttribute("loggedIn", new String("true"));
session.setAttribute("permission", new Integer(iPermission));
res.sendRedirect("index.jsp");
..
..
}
My problem is that when I try and access this session information in my "index.jsp" page, all values are null, and the session id's are different!
<%@ page errorPage = "Error.jsp" import = "java.util.*, javax.servlet.http.*, javax.servlet.*" %>
<HTML>
<HEAD>
<TITLE>KULIE</TITLE>
</HEAD>
..
<%=session.getAttribute("permission")%>
<%=session.getAttribute("loggedIn")%>
..
</HTML>
I have no idea what the problem is, and have stripped my code right down to the bare bones to see if I am making any stupid mistake.
I also triedgetting the session by using HttpSession userSess = request.getSession(); and displaying the results this way, but the values a re still null
Also, I have tested the following with 2 jsp pages, where 1 jsp page stores data in the session, then redirects to another page where the data is printed. The files are as follows:
v.jsp
<%session.setAttribute("andy", new String ("HELLO!"));%>
<% response.sendRedirect ("w.jsp");%>
w.jsp
<HTML>
<BODY>
<H1>
<%=session.getAttribute("andy")%>
</H1>
</BODY>
</HTML>
This works fine, so my problem only seems related to servlets.
Has anyone any idea on what could possible be causing the problem?
Thanks,
Andy Shiels