• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem of resubmisson in struts2

 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic