My application likes to pass value from AbstractInterceptor to two ActionSupport classes (codes below). When the user presses the Back button of a browser, hasValue() return true for class Action1. When the user presses the Back button of a browser, hasValue() return null for class Action2. My log show that request.setAttribute(KEY, Boolean.TRUE); //line A are executed for class Action1 and Action2. Where is the bug? Is it related to type="tiles" and type="redirectAction" in struts.xml? Please help. Thanks.
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.struts2.StrutsStatics; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class MyInterceptor extends AbstractInterceptor { public static final String KEY = "KEY"; @Override public String intercept(ActionInvocation invocation) throws Exception { HttpServletRequest httpServletRequest = (HttpServletRequest) ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST); final ActionContext context = invocation.getInvocationContext(); session = context.getSession(); HttpServletRequest request = (HttpServletRequest) context.get(StrutsStatics.HTTP_REQUEST); HttpSession httpSession = request.getSession(true); synchronized (httpSession) { httpServletRequest.setAttribute(KEY, Boolean.TRUE); //line A } } } import org.apache.struts2.interceptor.ApplicationAware; import org.apache.struts2.interceptor.RequestAware; import org.apache.struts2.interceptor.SessionAware; import org.apache.struts2.interceptor.ScopedModelDriven; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.Preparable; public class CoreAction extends ActionSupport implements Preparable, SessionAware, ApplicationAware, RequestAware { public boolean hasValue() { HttpServletRequest httpServletRequest = (HttpServletRequest) ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST); return Boolean.TRUE.equals(httpServletRequest.getAttribute(MyInterceptor.KEY); } } public class Action1 extends CoreAction implements ScopedModelDriven<Model1> { //... } public class Action2 extends CoreAction implements ScopedModelDriven<Model2> { //... } Struts version is 2.5.26. <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Virus-free. www.avg.com <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>