• 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

request.setAttribute()...

 
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?
 
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup. As I said: accepted and common practice.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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!
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic