Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Is this a good approach?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
    Bookmark Topic Watch Topic
  • New Topic