File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes session.getattribute question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "session.getattribute question" Watch "session.getattribute question" New topic

session.getattribute question

Randall Stewart

Joined: Aug 19, 2004
Posts: 2

I'm kind of new to the jsp world and have a question related to restoring html form fields dynamically using session.getattribute and javascript looping through the document.form.elements. Is there a way to do this. I am using WebSphere Development Studio Client as my development bench accessing an IBM Iseries DB2 data base through WAS 5.0. I am able to do it for each form element by name but there are many pages and many elements.

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211


If what you mean to do is to have a client submit a form, and then if you need to display it again, populate it with the data sent by the client, then you can do it with a combination of JSP-JavaBeans.

Create a JavaBean with instance member names matching the input element names in the form. When the user submits the form, use <jsp:setProperty> tag to store all the data submitted in the JavaBean. If you need to display the form again, use that bean to populate it with the values sent by client earlier.


The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Sonny's point is that you do not need to use client-side Javascript to accomplish this. In fact, that's a mechanism I would not recommend.

Use server-side JSP mechanims to set the value attribute of the form controls to the desired values.

[Asking smart questions] [About Bear] [Books by Bear]
Randall Stewart

Joined: Aug 19, 2004
Posts: 2
Thanks for the reply.

So this would reload all of the html form fields defined in the bean class from the session?

<jsp:setProperty name="xyz" property="*" />

and this would do just one of the elements?

<jsp:setProperty name="xyz" property="field" value="value"/>

How would I clear out the old data the next visit to the page from a prompt page?

Also where in the HTML form would I place the code? I have an onLoad function and onUnload already built.

I don't mean to be stupid with this but IBM has been NO help on this.

Thanks again for you patience.
I agree. Here's the link:
subject: session.getattribute question
jQuery in Action, 3rd edition