The situation is something like this. There are three pages page1,page2,page 3
Situation
Page1 >> takes to >> Page 2 >> takes to >> Page 3
Page 2 is an intermediate page, which has links and links contains the params required by the action to reach page3.
<a href="<s:url action="gotoPage3" includeParams="none">
<s:param name="request.accountId"><s:property value="#parameters['accountFrom.accountId']"/></s:param>
<s:param name="request.accountFromId"><s:property value="#parameters['accountFrom.accountId']"/></s:param>
</a>
What i want now
I want to get rid of page 2 so that
page1 >> takes to >> page 3
What I did
In the struts config, I gave the outcome of action associated page1 to chain it action associated with the page2 link.
<action name="processPage1AndGoToPage3" class="dominos" method="processPage1AndGoToPage3">
<interceptor-ref name="out-of-office-interceptor"/>
<interceptor-ref name="paramsPrepareParamsStack"/>
<interceptor-ref name="remove-hibernate-filters-interceptor"/>
<interceptor-ref name="request-deleted-interceptor"/>
<result name="success" type="chain">gotopage3</result>
</action>
Problem
Now how do i pass the params to the action associated with the page2 (which takes you to the page 3). (I was passing them through link before)
Any pointer will be helpful
<action name="processPage1AndGoToPage3" class="dominos" method="processPage1AndGoToPage3">
<interceptor-ref name="out-of-office-interceptor"/>
<interceptor-ref name="paramsPrepareParamsStack"/>
<interceptor-ref name="remove-hibernate-filters-interceptor"/>
<interceptor-ref name="request-deleted-interceptor"/>
<result name="success" type="chain">gotopage3</result>
<s:param name="page2Param1" value="page2Value1"/>
<s:param name="page2Param2" value="page2Value2"/>
</action>
Note that page2Param1 and page2Param2 will be passed to processPage1AndGoToPage3 the same way as calling http://server/webapp/processPage1AndGoToPage3.action?page2Param1=page2Value1&page2Param2=page2Value2
Related
This question already has an answer here:
Prevent same action called twice as long as user is in current session
(1 answer)
Closed 5 years ago.
I'm trying to avoid double-submit problems using tokenSession. My action methods are working fine without tokenSession technique.
I add <s:token/> in upsert_crypto_sources.jsp and tokenSession interceptor in struts.xml but I receive request as null in my action excludedMethod of list().
The list page doesn't need to avoid double submit problem but if I add <s:token/> in view_crypto_sources_list.jsp and remove list() from excludedMethod then I always receive result invalid.token.
My struts.xml is like:
<struts>
<package name="key-manager" namespace="/shared/km" extends="console-default" strict-method-invocation="true">
<action name="manage_cs_*" method="{1}" class="console.shared.km.ASC_ManageCryptoProfilesAction">
<interceptor-ref name="tokenSession">
<param name="excludeMethods">
list, initInsert, load, delete
</param>
</interceptor-ref>
<result name="list">/shared/km/view_crypto_sources_list.jsp</result>
<result name="insert">/shared/km/upsert_crypto_sources.jsp</result>
<result name="update">/shared/km/upsert_crypto_sources.jsp</result>
<result name="load">/shared/km/upsert_crypto_sources.jsp</result>
<allowed-methods>list, insert, load, update, delete, testConnection, forward, cancel</allowed-methods>
</action>
My action implements ServletRequestAware interface therefore it gets the request member variable set using setServletRequest() method.
I added a defaultStack interceptor and it is working fine:
<struts>
<package name="key-manager" namespace="/shared/km" extends="console-default" strict-method-invocation="true">
<action name="manage_cs_*" method="{1}" class="console.shared.km.ASC_ManageCryptoProfilesAction">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="tokenSession">
<param name="excludeMethods">
list, initInsert, load, delete
</param>
</interceptor-ref>
<result name="list">/shared/km/view_crypto_sources_list.jsp</result>
<result name="insert">/shared/km/upsert_crypto_sources.jsp</result>
<result name="update">/shared/km/upsert_crypto_sources.jsp</result>
<result name="load">/shared/km/upsert_crypto_sources.jsp</result>
<allowed-methods>list, insert, load, update, delete, testConnection, forward, cancel</allowed-methods>
</action>
this is probably an old question, but I just couldn't find an answer anywhere...
is there any way to prevent re-execute action in struts (other than re-direct to another page) when user clicks the refresh or back button on the browser?
index.jsp
<form action='call_action'>
<input type='text' name='name'/>
<s:token name="token"></s:token>
</form>
In struts.xml
<action name="call_action" class="controller.ActionClass">
<interceptor-ref name="token" />
<interceptor-ref name="basicStack"/>
<result name="invalid.token">invalid_token.jsp</result>
<result name="success">signup.jsp</result>
</action>
add invalid_token.jsp in your project.if unfortunetly user clicked second time.it automatically forward to invalid_token.jsp Page.
I have a few simple actions:
<action name="edit" class="EditAction">
<result>/WEB-INF/jsp/form.jsp</result>
</action>
<action name="preview" class="PreviewAction">
<result>/WEB-INF/jsp/preview.jsp</result>
<result name="input">/WEB-INF/jsp/form.jsp</result>
</action>
<action name="store" class="StoreAction">
<result>/WEB-INF/jsp/confirmation.jsp</result>
<result name="input">/WEB-INF/jsp/preview.jsp</result>
</action>
<global-results>
<result name="invalid.token">/WEB-INF/jsp/invalidToken.jsp</result>
</global-results>
and classic scenario: user interacts with text inputs, press Save, view a Preview page and press Save on it to save data, without double-press buttons, refreshing page etc.
Why double submit can occurs in such situation?
Even I had double form submit problem in struts2 on browser refresh. I resolved the problem using post-redirect-get pattern to avoid double or duplicate form submissions. It happens because hitting "refresh page" for a reponse based on a POST request will re-issue the POST request.It repeats what you did to reach current page even for double button press. It happens for both success and error in struts2.
I suggets you to make this change where-ever necessary.
<action name="onStoreRedirect">
<result name="success" type="redirect">store</result>
</action>
<action name="store" class="StoreAction">
<result>/WEB-INF/jsp/confirmation.jsp</result>
<result name="input">/WEB-INF/jsp/preview.jsp</result>
</action>
Im trying to make it so that once i submit this form i cannot hit the back button, but with the current configuration I cannot even get the page/form to load. I can't seem to figure out why "invalid.token" is always being triggered thus redirecting me to index.jsp no matter what I have the token tag in my form like im supposed to. If i use the "excludeMethods" filter and exclude View then my page loads but I can hit the back button freely so it still does not work properly. I have tried moving the interceptor-ref above and below my noLoginStack but it dosen't make a difference. Based on my debugging my actual java class isn't even being hit, so its failing before then. What am I doing wrong?
My action declaration:
<action name="viewAppointmentLetter" class="edu.ucr.c3.rsummer.controller.instructor.ManageAppointmentLetters">
<interceptor-ref name="noLoginStack"/>
<interceptor-ref name="token" />
<result name="invalid.token">/index.jsp</result>
<result name="error" type="redirectAction">index.do</result>
<result name="input">/instructor/assigned_appts.jsp</result>
<result name="view">/instructor/assigned_appts.jsp</result>
<result type="redirectAction">index.do</result>
</action>
My assigned_appts.jsp:
<s:form action="saveAppointmentLetter" onsubmit="return verifySubmit();">
<s:token name="token" />
.....
</s:form>
If its any clue I always get this in my console
WARN org.apache.struts2.util.TokenHelper - Could not find token name in params.
In struts2 the order of interceptor is very important. you should follow this order.
<interceptor-ref name="token"/>
<interceptor-ref name="noLoginStack"/>
USe TokenSession interceptor.Had to handle result by result name="invalid.token" in struts.xml in specific action.
The page from which your action is generated at that page you have to write <s:token> tag in the header
I use struts 2.1.8, I use <s:token> between <s:form> and </s:form>
in my struts.xml like that
............
<package name="user" namespace="/user" extends="struts-default">
<action name="login"class="user.UserAction">
<result type="tiles">login.view</result>
<interceptor-ref name="token"/>
<interceptor-ref name="basicStack"/>
<result name="invalid.token">/pages/error.jsp</result>
</action>
</package>
...............
at the first time, I run login.do action, I alway get error page. Plz give to me some suggestions thank in advance.
You need to add parameter to exclude method on which you dont want to apply interceptor
for example at the very first run I used populate method to populate my page
<interceptor-ref name="token">
<param name="excludeMethods">populate</param>
</interceptor-ref>
if you have more than one method than you can use comma to separate methods
<interceptor-ref name="token">
<param name="excludeMethods">populate,add,save,anyothermethod</param>
</interceptor-ref>
Best Luck !
Regards,
Asit Jaiswal
The problem is that your token is due.
If you choose to ignore the method, then you don't need to add the token tag