It's not a secret anymore!*
The moose likes Servlets and the fly likes Is this a good approach? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is this a good approach?" Watch "Is this a good approach?" New topic
Author

Is this a good approach?

Paul Gilette
Greenhorn

Joined: May 09, 2001
Posts: 10
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?
Mark Simms
Ranch Hand

Joined: Jul 20, 2000
Posts: 36
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");

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this a good approach?
 
Similar Threads
Why the form hidden field values can't be passed into servlet?
how to print values on jsp page fetched from servlet
Concerns about handling RemoteException on JSP view pages.
how to keep data from one request to another?
Dispatching request problem