Two Laptop Bag*
The moose likes JSP and the fly likes session problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

session problem

Erick Martin
Greenhorn

Joined: May 17, 2002
Posts: 8
Hi everybody. I am developing a web application following the MVC pattern. I have the feeling my so called �session problem� is quite trivial, but this is the price one has to pay when moving from the back-end scene to the jsp-servlet world. This is the scenario:
View:
There are a few pages having static content. For these pages the structure is as follow:
pageName.jsp � contains custom tags template
pageName.html � the actual content of the page
To increase performance, I use direct html links to access these pages, skipping over the main controller. So far, so good.
Controller:
MainServlet is the main controller. At this point it only does simple redirecting, you can take a peek at code below:
----------------------------
public class MainServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doProcess(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doProcess(request, response);
}
private void doProcess(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String nextScreen = null;
HttpSession session = request.getSession(true);
session.setAttribute("whateverAttribute", "attributeValue");
nextScreen = request.getParameter("currentScreen");
if (nextScreen == "x") {
gotoPage("/page1.jsp", request, response);
} else if (nextScreen == "admin") {
gotoPage("/page2.jsp", request, response);
} else {
gotoPage("/default.jsp", request, response);
}
}
private void gotoPage(String address, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(response.encodeURL(address));
dispatcher.forward(request, response);
}
}
------------------------
The problem:
I need to keep the session information generated in MainServlet (whateverAttribute=attributeValue) available to all my static jsp pages and eventually to other servlets, but every time I go to a new page I get a different session ID.
There are some conditional pieces of content to be embedded into the custom tags template, depending on session info.
Can anybody bring some enlightment to this troubled collegue? Thanks in advance,
[ May 17, 2002: Message edited by: sillyAgent ]

sa<br />Sun Certified Programmer for Java 2 Platform<p>"... black holes are those places in the Universe where God attempted to divide by zero"
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Please continue discussion in Servlet forum.
Thanks.
- madhav


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session problem
 
Similar Threads
servlet Session
Request Dispatcher probs
dispatcher.forward: sometimes it does not work!
session problem
RequestDispatcher.forward problem