Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

session.getattribute question

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Posts: 67399
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Randall Stewart
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Shiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic