Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with session and RequestDispatcher  RSS feed

 
jenny wang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet which handles infomation from several pages and forward result to jsp pages. But I got problem with IE browser.
It doesn't go to next page. I put object in the session at mainpage and rechieve the object at every following page.
//main page in doPost method
RequestDispatcher rd=null;
String next;
HttpSession session = req.getSession(true);
String sessionID = session.getId();
session.setAttribute(sessionID,MyObject);
if(MyObject.getType()==2)
next = "/2ndpage.jsp";
else
next="/3rdpage.jsp";
rd = getServletContext().getRequestDispatcher(next);
rd.forward(req, res);
//2nd and 3rd page
HttpSession session = req.getSession(true);
MyObject = (MyObject)session.getAttribute(session.getId());
//inside jsp page
<%@ page language="java" import="MyObject" session="true" %>
MyObject = (MyObject)session.get(session.getId());
I am using JRUN as my java application server and Iplanet server as web server. I believe there are many java experts in this JAVA salon. If somebody can point out the problem in my code I will appreciate your help. I will post more codes here if you need more details to understand the question.

jenny

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean it doesn't go to the next page?
Why are you doing this convoluted bit with the sessionID:
MyObject = (MyObject)session.getAttribute(session.getId());
You should be able to set and get the object with "MyObject" as a key - using the session ID just confuses things.
also, this code:
HttpSession session = req.getSession(true);
creates a new session if it can't find one. Seems to me that makes debugging harder - I think you want to:
HttpSession session = req.getSession(false);
if( session == null ){
// some debugging output here
}
Bill
------------------
author of:
 
jenny wang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William:
Thanks a lot for your code correct. Actually I did change the code to see the difference. But I still get error message after moving code from one server to another server(Jrun3.1 with Iplanet web server). The error message is as followed:
/test/TestServlet
java/lang.IllegalArgumentException: URI is null
at allaire.jrun.servlet.JRunSE.getRequestDispatcher(JRunSE.java:1937)
at TestServlet.doPost(TestServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760);
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(JRunSessionSevice.java:108)
at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java:76)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java:1552)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java:1554)
at allaire.jrun.servlet.JvmContext.dispatch(JvmContext.java:364)
at allaire.jrun.jrpp.ProxyEndpoint.run(ProxyEndpoint.java:388)
at allaire.jrun.ThreadPool.run(ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(WorkerThread.java:75)
Any idea?
jenny
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!