Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

request.setAttribute()...

 
Caine Lai
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was wondering if there is a big performance overhead with storing objects in the request. One way we would like to keep Java code out of our JSP's is to process all our Java code in a servlet and set the java objects into request scope to be used by the JSP. And then forwarding the request to the JSP for presentation.

Anyone see anything wrong with this from a scalability standpoint?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a thing.

What you are describing is a very common and accepted practice. Scoped variables placed into the various scopes using setAttribute() are merely entries in a Map, so there is very little overhead in creating/accessng them.
[ November 23, 2005: Message edited by: Bear Bibeault ]
 
Caine Lai
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason this came up is because we are using a mini-framework for our application since it is a small app with only about a dozen or so pages. By small I mean small in number of pages. But will need to scale to hundreds if not thousands of concurrent users.

We have a controller servlet that extends HttpServlet. The controller servlet handles all security authentication and initialization of data used in every page. Such as header data, etc.

And then we have one separate servlet for each .jsp view that handles the data processing for the view. Each of these servlets extends the controller servlet to handle the page specific data before forwarding it to the view.

So from an architectural standpoint do you think this sounds like it will scale adequately?
[ November 23, 2005: Message edited by: Than Long ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup. As I said: accepted and common practice.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bear said, it is very common and considered a "best practice".

In addition you may want to consider moving any of your core functionality out of the servlets (Controller) into beans (Model) so they can be run/tested without the need for a Servlet container to be running.

Also, while using inheritance (extending your controller servlet) is perfectly acceptable, you may find that the "Command" or "Front Controller" pattern will allow you to reuse even more code.

I have some really simple examples of these techniques on my site:
http://simple.souther.us

Look for SimpleMVC and SimpleCommand.

Good-Luck
 
Caine Lai
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!