File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Retrieving prepopulated form values in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retrieving prepopulated form values in jsp" Watch "Retrieving prepopulated form values in jsp" New topic

Retrieving prepopulated form values in jsp

Jera Blade

Joined: May 08, 2005
Posts: 15
Hi all,

I am a bit stuck on how to get the values i populated in a form bean in a action class to be displayed in my JSP.

I want to edit a user. Thus the user selects edit from the search screen and it goes to the editaction.class. In this class I populate a form bean lets call it editForm bean and put this into the session using the following code:

EditForm updateForm = new EditForm();
HttpSession session = httpServletRequest.getSession();
//httpServletRequest.setAttribute("updateForm", updateForm);
session.setAttribute("updateForm", updateForm);

The action class forwards onto the edit jsp which lets the user edit the first name.

however the value xxxxxxxx does not appear in the html text element of the jsp.

<td width="16%" height="36">
<html:text property="firstName"></html:text>

This will then be submitted again and is enclosed within a html:form tag which is not shown here.

Can anyone advise me on what I am doing wrong.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

Welcome to JavaRanch!

My guess is that the form is pointing to a different bean. Try posting the html:form tag and the relevant part of the struts config file.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jera Blade

Joined: May 08, 2005
Posts: 15
My struts config is as follows:

<action path="/actionClient"
<forward name="edit" path="/editClient.jsp"/>

The above action is called from the search page when i click the link edit.
I then put the createClientForm form in the session in this action class with the code posted previously. Should I be using actionClientForm here and why? as this does not hold the info I want displayed

<action path="/updateClient"
<forward name="failure" path="/jsp/failure.jsp"/>
<forward name="success" path="/jsp/success.jsp"/>

This is the updateClient action referred to in the edit jsp

In my edit jSP I have the following form tag:

<html:form action="/updateClient"

<td width="7%" height="36">
<div align="center">First Name:</div>
<td width="16%" height="36">
<html:text property="firstName"></html:text>

Ryan Dillon

Joined: May 24, 2005
Posts: 11
Hi Jera,

A couple of things. First I don't think you need to manually create and set the EditForm in the request. If you have defined the form in struts-config.xml and associated it with your action then it will be created automatically by struts and made available to you in the execute method.

However your example should still work. I think the problem there is that you have put the form under "updateForm" but in the JSP the action is "updateClient" which uses the form "createClientForm".

Hope that helps.

Ryan Dillon<br />Code Canvas Technologies<br />RapidJ - Rapid Java Web Development<br /><a href="" target="_blank" rel="nofollow"></a>
Jera Blade

Joined: May 08, 2005
Posts: 15

thats what it was i was referencing the wrong form when adding to the session.
I agree. Here's the link:
subject: Retrieving prepopulated form values in jsp
It's not a secret anymore!