This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm famiar with servlets and JSP, but not with Web application architectures. I need advice on the quality of an approach I'm trying... Thank you for taking the time to read this note and giving me your feedback. The application is used to view and update employee data. The URLs will have this structure: "action/viewpage/layout". For example, http://mysite/view/detail/default?id=123 is a request to view the employee with key (123), using the view page called "detail" and the layout "default". This works by having all requests go through a servlet called ControlServlet. The servlet fetches the object being requested and saves a reference to the object with the "request" using request.setAttribute("requstedObject", employee); I also save the view page request via request.setAttribute("requestedView", requestedView); The servlet then does a forward to the layout form (a JSP). The layout form uses dynamic (<jsp:include page=...> )incluces to bring in standard elements, such as a header, toc, and footer. Then uses the requested view to bring in the body of the requested document. The layout JSP fetches the requested view page via request.getAttribute("requestedView").toString(); The view page displays employee data. It fetches the data by doing this at the top of the JSP <% Employee employee = (Employee)request.getAttribute("requstedObject"); %> It then uses that object to show employee properties, such as <h1>Edit employee information for <%=employee.getName()%></h1> (I'm using this technique to avoid custom JSP tags -- that's a small level of additional complexity I'd rather not get into right now.) SO! My question is basically whether this looks like a good approach. I'm most up in the air about how to have the employee object and view request in scope as I'm forwarding from the servlet and including in the JSP. I could store it with the session object, but I seem to recall that a session is URL-specific, therefore, the object will be unavailable as the user goes from URL to URL. I need a scope that is for ONE USER across URLs on the site. Any suggestions or advice?
just change your scope to session vs. request. There will be only a minor penalty performance-wise for the app server. The session data will remain persistent from URL to URL until: 1) the user logs-out 2) the user fires-up another browser session (watch this !) 3) the appserver crashes just remember to remove the session attributes upon logout.... session.removeAttribute("x");