You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jipu Jiang <j....@nesc.gla.ac.uk> on 2009/09/16 18:46:06 UTC

form validation gets indefinite loops in web browsers

Hello everyone, 

Could anyone help me on an issue here? 

Here is the problem. I have a form in JSP to submit. But the parameters
in this form is not static, they are from a database. So I have an
action to be called first before enter the JSP page. It goes like this
in the struts.xml:

<action name="prepare" class="XXX">
	<result name="success">form.jsp</result>
	<result name="input" type="redirectAction"> prepare </result>
	<result name="error">error.jsp</result>
</action>

So if the parameters are ready, the request is going to be forwarded to
form.jsp. And JSP page will render these parameters into a form. If user
input right things, the page will go to next JSP page. But if user input
is wrong, the request is forwarded to prepare.action again for page
display. What I want to achieve here is to direct user back to the input
page, and they can see the values they just input, and error messages
will be there as well. 

This logic work fairly well if the form in JSP is static. But it wont
work in above situation. When I enter something wrong, the browser will
refuse the request, and display this message:

"Firefox has detected that the server is redirecting the request for
this address in a way that will never complete."

I can understand the browser's concern, but can anyone give me some
suggestions on how to get around this problem? The best scenario would
be to direct user back to the input page with error message and previous
values on it. 

Thank you in advance for any help here.

Cheers,
Jipu 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 form validation gets indefinite loops in web browsers

Posted by Dale Newfield <da...@newfield.org>.
Jipu Jiang wrote:
> So if user input something wrong, I want to show the original form.jsp
> page with all the parameters extracted from the database along with
> error messages. So I need to go to the prepareAction first to gets these
> parameters, and then display them in form.jsp page.

So make sure your prepare interceptor is before your validate 
interceptor, then forward (not redirect) to the input jsp.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Struts2 form validation gets indefinite loops in web browsers

Posted by Jipu Jiang <j....@nesc.gla.ac.uk>.
Struts2 form validation gets indefinite loops in web browsers

Continue on the last email:

So if user input something wrong, I want to show the original form.jsp
page with all the parameters extracted from the database along with
error messages. So I need to go to the prepareAction first to gets these
parameters, and then display them in form.jsp page. I tried to write
things like:

<result name="input"> prepare.action </result>

However, it doesn't work. So I used the redirectAction type. 

But this caused 2 problems:

1. when validating user input, the logic causes a indefinite loop. The
browser will detect this and stop forwarding after third loop.

2. error message lost during the redirectAction. As the actionError
stored in a map in session, this object gets lost during the forwarding.
I have to write this interceptor to keep actionError message in the
session. 

The root to all these trouble is just because I want to display error
message in the same page - form.jsp. I want user inputs stay in the
input fields, and error messages shows above the fields. If I can
persuade myself to display error messages on another jsp page, there
wouldn't be so much trouble. But just to wonder, is it possible to
achieve what I desired? Or is there any better design than what I did. 

Thank you very much for any help I can get. 

Cheers,
Jipu


-----Original Message-----
From: Jipu Jiang [mailto:j.jiang@nesc.gla.ac.uk] 
Sent: 17 September 2009 11:17
To: Struts Users Mailing List
Subject: RE: form validation gets indefinite loops in web browsers

Hi Dale, 

Thanks for reply. I have a form that needs parameters from an action. So
to see the JSP form, I'll have to go to the action first to prepare
these parameters for the form, and then the JSP form will render these
parameters. I'll show some sample code here.

PrepareAction.java

List<Parameter> parameters = new ArrayList<Parameter>();
Public String execute() throws Exception {
	Parameters = parameterService.getParameters(); // the service
will then gets parameters from database.
	Return SUCCESS;
}


Struts.xml

<action name="prepare" class="XXX">
	<result name="success">form.jsp</result>
	<result name="input" type="redirectAction"> prepare </result>
	<result name="error">error.jsp</result> 
</action>

Form.jsp

<s:iterator value="parameters">
	

</s:iterator>


What I want to achieve is to display the error messages along with the
submission page if user input something wrong. It would be better if
what user input can also stay on the submission page. 

-----Original Message-----
From: Dale Newfield [mailto:dale@newfield.org] 
Sent: 16 September 2009 17:55
To: Struts Users Mailing List
Subject: Re: form validation gets indefinite loops in web browsers

Jipu Jiang wrote:
> 	<result name="input" type="redirectAction"> prepare </result>

Why are you redirecting?

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: form validation gets indefinite loops in web browsers

Posted by Jipu Jiang <j....@nesc.gla.ac.uk>.
Hi Dale, 

Thanks for reply. I have a form that needs parameters from an action. So
to see the JSP form, I'll have to go to the action first to prepare
these parameters for the form, and then the JSP form will render these
parameters. I'll show some sample code here.

ReadAction.java

List<Parameter> parameters = new ArrayList<Parameter>();
Public String execute() throws Exception {
	Parameters = parameterService.getParameters(); // the service
will then gets parameters from database.
	Return SUCCESS;
}


Struts.xml

<action name="prepare" class="XXX">
	<result name="success">form.jsp</result>
	<result name="input" type="redirectAction"> prepare </result>
	<result name="error">error.jsp</result> 
</action>

Form.jsp

<s:iterator value="parameters">
	

</s:iterator>


What I want to achieve is to display the error messages along with the
submission page if user input something wrong. It would be better if
what user input can also stay on the submission page. 

-----Original Message-----
From: Dale Newfield [mailto:dale@newfield.org] 
Sent: 16 September 2009 17:55
To: Struts Users Mailing List
Subject: Re: form validation gets indefinite loops in web browsers

Jipu Jiang wrote:
> 	<result name="input" type="redirectAction"> prepare </result>

Why are you redirecting?

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: form validation gets indefinite loops in web browsers

Posted by Dale Newfield <da...@newfield.org>.
Jipu Jiang wrote:
> 	<result name="input" type="redirectAction"> prepare </result>

Why are you redirecting?

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org