• Post Reply Bookmark Topic Watch Topic
  • New Topic

Beans (again)  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • 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.
 
Tom E. Cole
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!