Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

session problem

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please continue discussion in Servlet forum.
Thanks.
- madhav
 
    Bookmark Topic Watch Topic
  • New Topic