|
Hi,
I have a question about session. Here is my test page. Actually, page1.jsp = page2.jsp, page3.jsp = page4.jsp and page5.jsp = page6.jsp. My problem is, when I click submit in page3 or page4, i get a null session id. But I click submit in page5 or page6, I get the same session id with page1 or page2. Why?? Is it after a change to mainframe2, the session will lost? Please help me to get the session in page3 or page4. Thanks. Louis ----------------------------------------------------------------------------------------------------- File Name : TestController.java Servlet import java.io.*;
import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class TestController extends HttpServlet
{
public static String ERRORPAGE = "error.jsp"
;
public static String JSPDIR = "/jsp/" ; public void init(ServletConfig config) throws ServletException { super.init(config); } public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String next; String cmd = null; try { cmd = req.getParameter("cmd"); HttpSession s = req.getSession(true) ; req.setAttribute("sid",s.getId()) ; next = cmd+".jsp"; } catch (Exception e) { req.setAttribute("javax.servlet.jsp.jspException", e); next = ERRORPAGE; } RequestDispatcher rd; rd = getServletContext().getRequestDispatcher(JSPDIR + next); rd.forward(req, res); } } ----------------------------------------------------------------------------------------------------- File Name : mainframe1.jsp <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <frameset rows="*" cols="200,*" frameborder="NO" border="0" framespacing="0"> <frame name="page1" noresize scrolling="NO" src="page1.jsp"> <frame name="page2" src="page2.jsp" marginwidth="0" marginheight="0"> </frameset><noframes></noframes> <body bgcolor="#FFFFFF"> </body>
</html> -----------------------------------------------------------------------------------------------------
File Name : page1.jsp <html>
<head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF">
<form name="form1" method="post" action="TestController"> <input type="submit" name="Submit" value="Submit"> <input type="hidden" name="cmd" value ="page3"> <p> </p> <p> </p> <p>Session Id: <%=request.getAttribute("sid")%> </p> </form> </body> </html> ----------------------------------------------------------------------------------------------------- File Name : page2.jsp <html>
<head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF">
<form name="form1" method="post" action="TestController"> <input type="submit" name="Submit" value="Submit"> <input type="hidden" name="cmd" value ="page4"> <p> </p> <p> </p> <p>Session Id: <%=request.getAttribute("sid")%> </p> </form> </body> </html> -----------------------------------------------------------------------------------------------------
File Name : page3.jsp <html>
<head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF">
<form name="form1" method="post" action="TestController" target="_top"> <input type="submit" name="Submit" value="Submit"> <input type="hidden" name="cmd" value ="mainFrame2"> <p> </p> <p> </p> <p>Session Id: <%=request.getAttribute("sid")%> </p> </form> </body> </html> -----------------------------------------------------------------------------------------------------
File Name : page4.jsp <html>
<head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF">
<form name="form1" method="post" action="TestController" target="_top"> <input type="submit" name="Submit" value="Submit"> <input type="hidden" name="cmd" value ="mainFrame2"> <p> </p> <p> </p> <p>Session Id: <%=request.getAttribute("sid")%> </p> </form> </body> </html> -----------------------------------------------------------------------------------------------------
File Name : mainframe2.jsp <html>
<head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <frameset rows="*" cols="200,*" frameborder="NO" border="0" framespacing="0"> <frame name="page5" noresize scrolling="NO" src="page5.jsp"> <frame name="page6" src="page6.jsp" marginwidth="0" marginheight="0"> </frameset><noframes></noframes> <body bgcolor="#FFFFFF"> </body>
</html> -----------------------------------------------------------------------------------------------------
File Name : page5.jsp <html>
<head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF">
<form name="form1" method="post" action="TestController"> <input type="hidden" name="cmd" value ="result"> <input type="submit" name="Submit" value="Submit"> <p> </p> <p> </p> <p>Session Id: <%=request.getAttribute("sid")%> </p> </form> </body> </html> -----------------------------------------------------------------------------------------------------
File Name : page6.jsp <html>
<head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF">
<form name="form1" method="post" action="TestController"> <input type="hidden" name="cmd" value ="result"> <input type="submit" name="Submit" value="Submit"> <p> </p> <p> </p> <p>Session Id: <%=request.getAttribute("sid")%> </p> </form> </body> </html> ----------------------------------------------------------------------------------------------------- File Name : result.jsp <html>
<head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body
bgcolor="#FFFFFF">
<p> </p> <p> </p> <p>Session Id: <%=request.getAttribute("sid")%> </p> </body> </html> |
- Session question! Louis
- Session Question! Louis
- Session Question! Louis
