jsp page contents..

I have too many form elements in my jsp page. So i want to break this page into 2 pages, probably thinking of having a next and prev button on my first jsp page. Also i want to process all the form elements( ie both page 1 and 2 )and store the user entered info into database. Could anyone please suggest me how this can be done. Do i need to use <jsp:forward> tag for this to be done if i want to split my form elements into 2 pages. Appreciate your help! Thanks.

Hey Mandy, I believe it should not be too difficult. From the first page you may take the form data to your servlet/JSP and then populate your object(s) with the data received from the request object, now you can either put this object(s) in session or you may pass your object(s) with the response to the next jsp page using response.setAttribute(). In the latter case you will have to do request.getAttribute() and then response.setAttribute() in second JSP, but if u decide to put you objects in session then u can just get it back when u are ready to put them in the database, just make sure you specifically unset the session attribute after u insert your data in the database.

Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62

posted Oct 10, 2001 12:53:00

0

Thanks. I will give it a try.

Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62

posted Oct 11, 2001 10:19:00

0

Hi Dharmesh, I am thinking of storing this object in the session. You mentioned the other way to do this by passing along with the response object's setAttribute() method. Could you please let me know how this can be done with some sample code if you would, i am just curious to know and have never done this kind before. Also i don't see any setAttribute() method of response object. Appreciate your help! Thanks.

HI, On the first page, using request.setAttribute("data1", Obj) { HttpServletRequest }to store your object and later on the second page, use request.getAttribute("data1") to dump the Obj. Hope it helps. ---Yongping

[This message has been edited by Yongping Wang (edited October 12, 2001).]

Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62

posted Oct 12, 2001 09:09:00

0

I don't see any method called setAttribute for this response object in my documentation. Is there a method like this one. response.setAttribute("data1", Obj) Appreciate your help, Thanks.

The attribute set in the request survives only for the lifetime of the request. When the second page gets displayed the request (which started when 1st page was submitted) dies. The values entered in the 1st page can be stored in hidden fields in the second page (if you'r not using the session). [This message has been edited by sanjay yermalkar (edited October 12, 2001).]

Dharmesh, What version of the specification has response.setAttribute? Mandy, You have a lot of options, among them, you can store the values in a bean, store them in a session object, or append them to the call to your next page. For the experience, I would look at both beans and sessions (you would probably give the bean session scope, so you will need a bit of session knowledge). I think sticking them in the session is simpler unless you really have a ton of stuff then a more specialized bean would probably be better. request.set/getAttribute is really not what you are looking for on this. You are not forwarding the request to the next page, you are going to have two seperate requests. Andrew

HI, Why not use one page that submits to itself? Just check one of the second group of values to be null in an if statement and place the first form in the if part and the second form in the else part. The second form will have a different action command so you can stay on that page with another if and process it there or go to some other page/bean/servlet. This way the values all accumulate and as the JSP is already compiled and instantiated the jump from the if to the else is very fast.