struts2-interceptors

How can I configure HTTP Response Headers in a Struts2 Interceptor?

此生再无相见时 提交于 2019-12-10 18:24:02
问题 We currently have a java web application in the middle of migration from Struts 1 to Struts 2. We would like to configure X-Frame-Options and Content-Security-Policy headers for all our Struts 2 actions. We have a lot of actions and I want to avoid modifying them all separately if at all possible. the idea I currently have is the following interceptor which would be added to the default stack: import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext;

Why the Exception raised from my Interceptor is not caught by <global-exception-mappings>?

跟風遠走 提交于 2019-12-10 11:07:49
问题 I have a custom Interceptor, from which I throw an Exception; The Action(s) running that Interceptor is managed by Convention plugin; The Exception raised by the Interceptor is globally defined in struts.xml for the package the Action is running into. RESULT: the exception mapping is ignored and I get the Struts Problem Report Struts has detected an unhandled exception: ... Stacktraces java.lang.IllegalArgumentException: my message I guess I'm just missing something stupid... we've already

How to call an action method using OGNL

心已入冬 提交于 2019-12-08 20:04:39
How to call an action method using OGNL? helloAction.java public String getQuote() { return "Don't think, just do"; } success.jsp <b>quote() :</b> <s:property value="quote()"/> <br> struts.xml <action name="greet" class="com.struts2.helloAction" > <interceptor-ref name="firewallStack"></interceptor-ref> <result name="SUCCESS">/WEB-INF/resources/success.jsp</result> <result name="input">/WEB-INF/resources/success.jsp</result> </action> I got the ref link from struts 2 OGNL This quote() method is not called. I am using xwork-2.0.1.jar and ognl-2.6.11.jar. This quote() method is not called. I am

How to have access to ServletRequestAware on struts2-core 2.3.16.1?

不羁的心 提交于 2019-12-08 13:57:53
问题 I changed my struts2 version from 2.3.14 to 2.3.16.1, it seems that newest version does not support ServletRequestAware and ServletResponseAware anymore, what should I do? I could not find anything online. <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.16.1</version> <type>jar</type> </dependency> Code import org.apache.struts2.interceptor.ServletRequestAware; public class MyExample implements ServletRequestAware, ServletResponseAware {

java.lang.ClassCastException during action chaining - from Struts 1 to Struts 2

心不动则不痛 提交于 2019-12-08 10:52:23
问题 We have Struts 1 application.We need to migrate to Struts 2. With minor change.We are not going to change anything in Action class. We are using existing action class and Action Form. Action is getting triggered without any issues. But action chain is not working as expected. We are using many values from LoginAction to FetchInboxAction. Both are using two different form. Please find the sample struts.xml and error stack. The chain action is not working for us. Currently we are getting the

struts2 StrutsPrepareAndExecuteFilter customization

怎甘沉沦 提交于 2019-12-08 08:20:57
问题 We are using struts2 StrutsPrepareAndExecuteFilter . The configuration in web.xml is: <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> <init-param> <param-name>struts.devMode</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> We need to implement authentication/permission inside

How to disallow caching in struts2?

走远了吗. 提交于 2019-12-08 04:42:51
问题 In my web application, when the user logs out, he should not have access to pages he's previously viewed while he was logged in. However, due to browser caching, he can view those pages when clicked on the back button. I defined an Interceptor to handle this: public String intercept(ActionInvocation invocation) throws Exception { // TODO Auto-generated method stub final ActionContext context = invocation.getInvocationContext(); HttpServletResponse response = (HttpServletResponse)context.get

execAndWait Interceptor not redirecting to success page after waiting

江枫思渺然 提交于 2019-12-07 23:06:52
问题 I have a login screen where some user input validation will happen, the user will be authenticated and finally redirected to the welcome screen. Below is the interceptor definition for the LoginAction : <package name="default" extends="struts-default" namespace="/"> <interceptors> <interceptor name="myInterceptor" class="com.interceptor.MyInterceptor"></interceptor> <interceptor-stack name="newStack"> <interceptor-ref name="myInterceptor"/> <interceptor-ref name="defaultStack" /> <interceptor

struts2 StrutsPrepareAndExecuteFilter customization

允我心安 提交于 2019-12-06 14:56:17
We are using struts2 StrutsPrepareAndExecuteFilter . The configuration in web.xml is: <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> <init-param> <param-name>struts.devMode</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> We need to implement authentication/permission inside this common interceptor. What will be the easy way for it? Can we create a customized interceptor which

Retaining values between multiple JSPs and Actions in Struts 2

瘦欲@ 提交于 2019-12-06 14:29:38
问题 My struts project structure is as follows: page1 -> action1 -> page2 -> action2 -> page3 What i need is for a value i entered in an input tag in page1 to be accessed in action2. Here is my code: page1: <div class = "container"> <s:form id = "idinput" method = "post" action = "idEntered"> Enter id: <input id = "txtid" name = "txtid" type = "text" /> <input id = "cmdsubmit" name = "cmdsubmit" type = "submit" value = "enter details" /> </s:form> </div> action1: public class AddId extends