Servlet and cascaded JSP beans

HI,

being a novice in JSP programmi I fell into a problem I hope sombody will help to solve!

I have a form in a first JSP page. When user submits the form another JSP checks for the correctness of the data then passes evertyhing to the servlet for elaboration.

So at this point the bean is first created in the first JSP page, the properties are set up in the second JSP file and the elaboration of data takes place in the servlet. (article wich inspired me is at http://www.javaworld.com/javaworld/jw-03-2000/jw-0331-ssj-forms.html)

At this point, the result I recorded in the bean is successfully displayed back in the first JSP page. Here's the problem: when execution passes to the servlet again I'm not able to get the elaboration data back from the bean!

I suppose that this happens because the <setProperty *> isn't in the first JSP but the second: if I insert SetProperty statements (just for testing) in the first jsp (wich contains the form) bean data won't change.

Can somebody help me to catch the design flows? Any help would be greatly appreciated!!!!

Thanks,

Matteo

[1148 byte] By [Jangaliana] at [2007-11-26 21:01:21]
# 1

Where are you storing the bean? Page, request or session context? If you want the bean to exist between requests you should store it in session

request.getSession().setAttribute("whatever", bean);

Edit:

Just checked the article. It's storing the bean on the request (where it actually belongs ;-)) That's why it "disappears between requests. If you really need it after the request has been serviced (the servlet/jsp finish their work) store it on the session as previously suggested. Otherwise recreate it as you did in the first place (with the login form)

Message was edited by:

benubach

benubacha at 2007-7-10 2:32:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for the explaination!

I don't want to use session bean, so I'd like to recreate the bean. How do I achieve this?

Is it sufficient to crate in the servlet a new bean and then do a request.setattribute ?

edit:

I have modified my bean to display the result of a db query. Each row is listed as a checkbox. After the user submit data I can read the checkboxes value but not the list wich generate the checkboxes itself, previously recorded in a bean field (with getter and setters).

So I'm forced to do another query to get values (note: the fields entered by user are perfectly accessible again, that's the strange thing!!!)

Furthermore I tried to put session in the scope of the jsp files but i get only errors...

Jangaliana at 2007-7-10 2:32:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

The bean's fields submitted by the user are accesile because your "form handler" instantiates the bean and sets the corresponding fields out of the form data, isn't it? The DB query results are not there because you're not storing them anywhere ;-)

And yes, you can instantiate a bean and do a request.setAttrribute() to use it in the JSP.

I don't have the slightest idea of how are you trying to put the user session in the page scope... and i don't dare to ask... :-p But post the code (between code tags please) and the error received and we can work on it.

benubacha at 2007-7-10 2:32:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...