wood burning stoves 2.0*
The moose likes Struts and the fly likes Problem of resubmisson in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem of resubmisson in struts2" Watch "Problem of resubmisson in struts2" New topic
Author

Problem of resubmisson in struts2

biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
Hi all,
I am facing a problem of resubmition in struts. I had filled a page and submitted it. its is gone to my db and agin redirected to the same page . All data that i previously entered is filled in those fields. and if i am ginve refresh by right clicking the broswer the last trasaction agin happening and the page get submitted. HOw can i resolve this page


Biny Balan
binypanackal@gmail.com
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Well Struts 2 has the token interceptor to handle this. You just have to configure it into your action, and use <s:token/> tag in your form which gets submitted. I saw somewhere on the internet that you might need to add this type of result to your action



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72

Action to the page through with i am Listing data [blgCreateQuestionCategory page is used]
The same page also have an input box to enter the value and a submit button



Action to insert the value. after inserting i am rediectint to the same action that also redirect to same page
then i am refreshing the page the "InserQuestion" is happening aging

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I can't really figure out what you're trying to say, but am quite suspicious of the action chaining. There's almost *never* a reason to do action chaining. If you're on the page that chained to the "ListQuestionCategory" action and refresh the page you'll re-submit--the chain isn't a new request.

You might want to look up the post-redirect-get (or whatever it's called) for why it happens and some ways to avoid it.
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
Wht i want to do is..
I had page which displays list of category. and i have a text box and a submit button to insert new category
i have an insert method inside my action class through wich i am insring the new entry. so on the submit button click i am calling that method. But i am filling the list that need to be show in the page is in exec method. So when i am calling the insert method and dircting to the same page it wont lits those which i inserted
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
Now i changed my code like this

Action




Struts.xml



Now the text box get cleared and my on refresh its agin getting submitted



JSP


<s:form >
<s:textfield name="qstCategory" label="Enter Question Category"/>
<s:submit action="InserQuestion"/>
</s:form>

<DIV style="border:1px solid white; float:left;"> <s:iterator status="stat" id="qstCategoryList" value="qstCategoryList"> <s:if test="%{(#stat.index%2)==0}"> </s:if> <s:else> </s:else> </s:iterator>
<s:property value="value"/> <s:property value="value"/>

</DIV>




waiting for a solution
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And I'm telling you that you'll need to use the post-REDIRECT-get pattern to avoid the issue.

If the last request made is a redirect-get if you refresh you'll just get the same page--the one without the form submission.

Or you can use <s:token> and all that, but IMO the PRG pattern is simpler.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem of resubmisson in struts2