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: Erick Martinez ]