top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Struts: Token Session Interceptor and back button

+1 vote
842 views

I am using the token session interceptor for a form and I have this situation:
1) I am in the form page;
2) I leave the form page;
3) Go back to the form page by the "back" button;
4) Submit the form;

And of course the form is not submitted and the token returns "invalid.token" but do not adds no actionError. It will not be interesting to add an action error?

Ok, I can resend to a page with a message but I already have a error page that presents the action errors when necessary.

posted Dec 5, 2013 by Deepak Dasgupta

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button
Make sure your back-button action refreshes the page. You can't reuse a token from the browser's cache. It needs to regenerated.

2 Answers

+1 vote

@Garima, I was thinking about this example...what did you have in mind as a way to achieve that, tough, i.e., that a browser "back" refreshes the page?

I can only see some javascript method/hack for that. Were you thinking of something else?

answer Dec 6, 2013 by Bob Wise
+1 vote

You need to have browser caching disabled on your first page:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
response.setHeader("Pragma", "no-cache"); // HTTP 1.0
response.setDateHeader("Expires", 0); // Proxies
answer Dec 6, 2013 by Luv Kumar
Similar Questions
+1 vote

I would like to dynamically insert an interceptor to a specific place in existing stack.

Of course I also like the stacks referencing the one where I insert the interceptor also take advantage of this configuration change.

I started to look on the side of PackageProvider, but I can not find sufficiently complete documentation allowing me to do this.

+1 vote

In struts2 , defined an interceptor, it triggered by Action, my question is

"inside the interceptor class, what is the function call that can tell caller's name, because that interceptor could be triggered by different Action, we need to log the caller's name, but how?"

0 votes

I have encountered this issue a couple of times, always found a way to code around but now I really need to ask:

Can struts create lists/arrays (or whatever collection) when e.g. using

public class MyAction extends ActionSupport {
 public List getChoices() {
 ....
 }
 ....
 public List getPreSelectedChoices() {
 // returns a list of Choice.getKey(), which is a String
 ....
 }
 }

 public class Choice {
 public String getKey() { ...}
 public String getDisplayName() { ... }
 ....
 }

The selected values are sent to

public void setMyChoice(String myChoice){
 ...
}

correct? There is no way something like

public void setMyChoice(String[] myChoice){
 ...
}

works in struts?

If not, whats the common way to get the values back from the String myChoice? Use Split on it?

+7 votes

I have an Interceptor that wants to put something in the session after the action has executed.

But if the session doesn't already exist I get an exception:

java.lang.IllegalStateException: Cannot create a session after the response has been committed

How can I determine if the session already exists from within an Interceptor?

 public String doIntercept(ActionInvocation invocation) throws Exception
 {
 String result = invocation.invoke();
 Map session = invocation.getInvocationContext().getSession();
 session.put(key, value); // throws exception if session doesn't exist
 return result;
 }
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...