• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Beans (again)

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have another problem with beans if anyone is interested.
My JSP (Validate.jsp) collects user information from another JSP, then it creates a bean.

My servlet(Spreadsheet.java) now recieves the bean, and its properties are displayed.

The problem is, the servlet(Spreadsheet.java) only displays the bean, when the page is loaded, so if many users enter information, the single bean I'm using will just keeping changing, and only the latest version will be displayed when Spreadsheet.java is executed.

I'm not keen on using multiple beans, and them letting the servlet display the properties for all of them when it is loaded, for 2 reasons:
1. I would need to name each bean object, seperately
2. This may in principle require thousands of beans.

I would like the bean (after its properties have been set) to have its properties stored in an array perhaps, in the servlet.
Is this approach possible??? any thoughts are welcome.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wouldn't need to name each bean separately if it was stored in the session. You retrieve the session from the request, which is a unique, persistent session per user. Therefore when you store and retrieve the bean from the session, you're getting the bean for whatever user has made the request.

Your bean should also be sure to release any unneeded references between requests (like database connections, etc.).

HTH.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other words, instead of storing your bean in application scope (ServletContext) where it is available to all users, store your bean in Session scope
The code is remarkably the same, you just call session.setAttribute() rather than servletContext.setAttribute, and make the bean scope="session" on your jsp page.

nb: you get a session in a servlet by calling request.getSession();
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but my code still isn't exactly how I want it.
I've changed scope to "session", and I can easily print
out the properties from 1 bean in a different servlet.

But suppose 10 people use the site, and they each create a bean.
Then I don't have a clue how to display the properties of all these
beans at the same time in a jsp/servlet when the jsp/servlet is displayed.

This jsp/servlet is linked to from the website, and is basically required to collect users details. So when ever some one links to this jsp/servlet, it might be a different session to the sessions the other beans were created in. So I'm totally confused about how to do what's in Paragraph 2 above.

Any help is appreciated
[ August 08, 2005: Message edited by: colin shuker ]
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic