How can JSP page get correct session object?

marcow (UserMarco)
<本文发表于: 相约加拿大:枫下论坛 >
I wrote a java servlet and I'd like to forward the request to an JSP page. Just like below:


public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
HttpSession session = Request.getSession (true);
ObjA myObj = (ObjA) session.getAttribute ("MyObj");
if (myObj == null) {
myObj = new ObjA ();
session.setAttribute ("MyObj", myObj);

RequestDispatcher dispatcher
= getServletContext().getRequestDispatcher("myJsp.jsp");

In myJsp.jsp, I used
<%ObjA myObj = (ObjA) session.getAttribute ("MyObj")%> to retrieve the same myObj instance.

When the Servlet is invoked first time, it create myObj and store it in session object. Then request is forwarded to JSP page, and then return output to client. Everything works well.

But how this JSP page can get same myObj from session? JSP should know the sessin id of course, sesssion id can be retrieved from cookie or URL rewriting, but at this moment, the response is not return to client broswer yet, so there is not cookie or other thing set on broswer side. JSP page should get the correct session id from applicatin server. But how can JSP page get it? Where does JSP get it?

Thanks in advance.

<本文发表于: 相约加拿大:枫下论坛 >

2000-10-29 -04:00

回到话题: How can JSP page get correct session object?

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论