All, Ok, here's what I am currently attempting to do. 1.)I have a JSP with multiple text fields and a couple of selection boxes and a submit button. 2.)The user fills in all of these fields in the JSP and hits a submit button. 3.)An ActionForm collects the inputted values from the different fields and an Action class does some stuff with these values. (This all works great) 4.)After the Action class does what it has to do successfully it will then forward to another JSP page that informs the user that the action completed successfully. (This works great too) 5.)The user then has the option of using a link to return to the previous JSP with the text fields, selection boxes, and submit button. (Here's my problem) I want this JSP's text fields to be cleared and its selection boxes to have their default values shown when I return to it from this other JSP. I am doing some validation on the input when the user submits the data. Basically, if the user does not enter something into a few specific fields then after they press the submit button struts will refresh the page and display the errors. ALL previously entered fields must retain their values here, hence why I can't use a request scope for the action. It is only after I return to this form from another JSP do I want all the fields to be reset. I am not sure how to make this happen. I have tried many things with no success so far. I know the solution is most likely simple but I don't see it and my attempts to find an example on the web have come up miserably short. Please help if you can. Thank you, Chad Schmidt
Hi Chad, Given that you want to clear out the Form when you come back to the page (and it is not happenning), I think one of these could be the culprit: 1) You are using a session scoped ActionForm. Change your Action Mapping to use Request Scope 2) You are using a request scoped form, but the browser is caching the page, thereby displaying the older values. (For e.g. in IE you could be using the option to "Never" refresh the page). Try adding the following to the HTTP Headers: In HTTP 1.0, you have to set the following HTTP headers to skip browser cache. 1) Set Expires field to be 0 or less than or equal to current time. Expires: Sun, 01 Apr 2001 18:32:48 GMT 2) Set Pragma: no-cache Under HTTP 1.1, additional setting is needed to set the Cache-Control header as Cache-control: no-cache or Cache-control: no-cache,max-age=0 If the above does not solve your problem, try appending a random number to the URL in your second JSP. Browsers often cache pages with links. Appending the random number to the link forces the browser to re-fetch the page
OK Chad ! The first problem can be solved as following: - When going back to previous pages, link to some Action that mapping to the page's path (also its ActionForm). Call the method reset(...) of ActionForm. Then the value will be reseted. You can also call your own function to clear it. The second: - OK, you can use th way as some replies posted, by caching... One way you can do is storing information of the pages when submitting to some variables. And then when you reforward to it, it will display your old value. If you still fail with your code, plz contact me as: firstname.lastname@example.org Good luck ! HuyNT
Hi Chad, Firstly, you make the point that you need a session scoped bean in order that the page retains the values you enter when you return to it on an error. Using Struts, you don't need to do this. If you are use
to return on error, the request scoped form bean will be returned to the input page (i.e. your form) and it's values used to repopulate the boxes on that form. Using a request scoped bean may also help to remove your caching problem. Another possibility is to call
just before your action forwards to the sucess page defined in your struits config for this action. This will remove the form bean mapped in your struts action from the request scope, so it will not be available to any future pages. Hope that helps...