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

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 below error:
225760 [http-nio-8080-exec-8] ERROR org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler - Exception occurred during processing request: com.InboxForm cannot be cast to com.LoginForm
java.lang.ClassCastException: com.InboxForm cannot be cast to com.LoginForm
at com.LoginAction.execute(LoginAction.java:104)
at org.apache.struts2.s1.Struts1Action.execute(Struts1Action.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:891)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)
at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369)
at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.Ognl.getValue(Ognl.java:494)
at ognl.Ognl.getValue(Ognl.java:458)
at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:309)
at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:340)
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:307)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:423)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:287)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:250)
at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at com.opensymphony.xwork2.ActionChainResult.execute(ActionChainResult.java:233)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:369)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:273)
at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.SecurityAccessFilter.doFilter(SecurityAccessFilter.java:105)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
struts.xml:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="PackageName" namespace="/"
extends="struts1-default">
<interceptors>
<interceptor name="LoginForm"
class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor">
<param name="className">com.LoginForm</param>
<param name="name">LoginForm</param>
<param name="scope">request</param>
</interceptor>
<interceptor name="InboxForm"
class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor">
<param name="className">com.InboxForm</param>
<param name="name">InboxForm</param>
<param name="scope">request</param>
</interceptor>
<interceptor-stack name="web">
<interceptor-ref name="staticParams"/>
<interceptor-ref name="LoginForm"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
<interceptor-stack name="web2">
<interceptor-ref name="staticParams"/>
<interceptor-ref name="InboxForm"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
</interceptors>
<action name="LoginAction" class="org.apache.struts2.s1.Struts1Action" method="execute" >
<param name="className">com.LoginAction</param>
<interceptor-ref name="web"/>
<result name="success" type="chain">FetchInboxAction</result>
<result name="failure">/error.jsp</result>
</action>
<action name="FetchInboxAction" class="org.apache.struts2.s1.Struts1Action" method="execute">
<param name="className">com.FetchInboxAction</param>
<interceptor-ref name="web2"/>
<result name="success">/sucess.jsp</result>
<result name="failure">/error.jsp</result>
</action>
</package>
</struts>

In struts.xml for fetchInboxAction all interceptors are called again due to this after executing LoginAction instead of invoking FetchInboxAction it invokes LoginAction with InboxForm.In Action class Action form is typed casted to LoginForm but in run time we got FetchInboxForm. This is due to wrong config.
After the below changes Action chin is working without any issue.
Modified Struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="PackageName" namespace="/"
extends="struts1-default">
<interceptors>
<interceptor name="LoginForm"
class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor">
<param name="className">com.LoginForm</param>
<param name="name">LoginForm</param>
<param name="scope">request</param>
</interceptor>
<interceptor name="InboxForm"
class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor">
<param name="className">com.InboxForm</param>
<param name="name">InboxForm</param>
<param name="scope">request</param>
</interceptor>
<interceptor-stack name="web">
<interceptor-ref name="staticParams"/>
<interceptor-ref name="LoginForm"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
<interceptor-stack name="web2">
<interceptor-ref name="staticParams"/>
<interceptor-ref name="InboxForm"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
</interceptors>
<action name="LoginAction" class="org.apache.struts2.s1.Struts1Action" method="execute" >
<param name="className">com.LoginAction</param>
<interceptor-ref name="web"/>
<result name="success" type="chain">FetchInboxAction</result>
<result name="failure">/error.jsp</result>
</action>
<action name="FetchInboxAction" class="org.apache.struts2.s1.Struts1Action" method="execute">
<param name="className">com.FetchInboxAction</param>
<interceptor-ref name="InboxForm"/>
<result name="success">/sucess.jsp</result>
<result name="failure">/error.jsp</result>
</action>
</package>
</struts>

Related

after using token interceptor in my application getting exception

<interceptors>
<interceptor-stack name="appDefault">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
<interceptor-ref name="tokenSession">
<param name="includeMethods">upload,view,delete,confirm</param>
</interceptor-ref>
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/jpeg,image/jpg,image/png,image/pjpeg,application /pdf</param>
<param name="maximumSize">1048576</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="appDefault" />
<action name="upload_*" class="nic.rto.sow4.actions.UploadAction" method="{1}">
----
-----
<result name="invalid.token">/jsp/invalid_token.jsp</result>
</action>
This exception occurred:
SEVERE: Servlet.service() for servlet default threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:914)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:574)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Try to configure interceptor for individual action as given below.
<action name="yourAction" class="com.YourActionClass">
<interceptor-ref name="tokenSession"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success">/success.jsp</result>
<result name="input">/update.jsp</result>
</action>

struts 2 token Interceptor

I am getting like "WARNING: Could not find token name in params."
In Struts.xml
<interceptors>
<interceptor name="entityInterceptor" class="entity.jpa.EntityInterceptor"/>
<interceptor name="sessionInterceptor" class="env.actionitems.struts.SessionInterceptor"/>
<interceptor-stack name="entityStack">
<interceptor-ref name="entityInterceptor"/>
<interceptor-ref name="sessionInterceptor"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="defaultStack">
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="entityStack"></default-interceptor-ref>
<action name="*acegitran*jsp*pkg*create*dcode*" method="{1}" class="env.transactions.{3}.{4}">
<interceptor-ref name="token"/>
<interceptor-ref name="entityStack"/>
<result name="invalid.token">Transaction.{2}iport{5}create</result>
<result name="success" type="tiles">Transaction.{2}iport{5}create</result>
<result name="error" type="tiles">Transaction.{2}iport{5}create</result>
<result name="input" type="tiles">Transaction.{2}iport{5}create</result>
</action>
In JSP
<s:token name="clientToken"/>
Any other parameters should be passed in struts.xml to solve.
I had a similar problem. You might want to try changing "invalid.token" to "invalid.clientToken" in the Struts.xml file
eg
result name="invalid.clientToken"
Please remember that the Struts.xml file will only take effect after the server is restarted!
Hope that helps

validation failing yet its still running execute on struts2

im doing a modification on an existing app. my problem is even tho the validation fails for the form submit, its still executing the execute method.
my struts file
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- <include file="com/paritysys/util/struts.xml" /> -->
<constant name="struts.url.includeParams" value="none" />
<constant name="struts.action.extension" value="html,action" />
<package name="public" extends="struts-default">
<interceptors>
<interceptor name="websiteOnline"
class="parity.action.website.OnlineInterceptor" />
<interceptor name="websiteLogin"
class="parity.action.website.LoginInterceptor" />
<interceptor-stack name="appStack">
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<!-- <interceptor-ref name="paritySessionStack"/> -->
<interceptor-ref name="websiteOnline" />
<interceptor-ref name="websiteLogin" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="appStack" />
<global-results>
<result name="login" type="redirectAction">
<param name="actionName">index</param>
</result>
<result name="exception" type="freemarker">/public/error.html.ftl</result>
<result name="error" type="freemarker">/public/error.html.ftl</result>
<result type="freemarker" name="maintenance">/public/maintenance.html
</result>
<result type="freemarker" name="pre-offline">/public/pre-offline.html
</result>
<result type="freemarker" name="post-offline">/public/post-offline.html
</result>
</global-results>
<action name="index" class="parity.action.website.LoginAction">
<result type="freemarker" name="success">/public/index.html.ftl</result>
</action>
<action name="login" class="parity.action.website.SubmitLoginAction">
<result type="freemarker" name="success">/public/questionnaire.html.ftl
</result>
<result type="freemarker" name="input">/public/index.html.ftl</result>
</action>
<action name="submit" class="parity.action.website.SubmitQuestionnaireAction">
<result type="freemarker" name="success">/public/thanks.html.ftl
</result>
<result type="freemarker" name="input">/public/questionnaire.html.ftl
</result>
</action>
<action name="whereIsMyId" class="parity.action.website.LoginAction">
<result type="freemarker" name="success">/public/whereIsMyId.html.ftl
</result>
</action>
<action name="loadCollegeFinder" class="parity.action.website.LoadCollegeFinderAction">
<result type="freemarker" name="success">/public/college_finder.html.ftl
</result>
</action>
<action name="findCollege" class="parity.action.website.FindCollegeAction">
<result type="freemarker" name="success">/public/college_finder.html.ftl
</result>
<result type="freemarker" name="input">/public/college_finder.html.ftl
</result>
</action>
</package>
my action class code
public void validate() {
logger.debug("validate fired");
Bla bla bla
addFieldError("username","error");
if (hasFieldErrors()) {
logger.debug("Field errors is true");
}
}
public String execute() throws Exception {
logger.debug("execute firing");
return result;
}
any ideas why this would happen? for some reason even tho the login.action is failing, its still sending down the success return and moving forward.
You interceptor stack doesn't include the "workflow" interceptor stack, which is what determines what to do on a validation failure.
For that matter, it doesn't include the "params" interceptor, which is how parameters are set on the action, so it will never work anyway. You can't just arbitrarily remove interceptors--it's where S2 gets the bulk of its functionality. See the interceptor docs.
Also, you can set a default result type--you may want to do that if most everything is a FreeMarker result rather than type it over and over.

struts 2 Bean does not populate in action class

I am using Struts 2-Spring framework in my assignment.
I have defined a bean in struts 2 action class
One interceptor for checking authorisation before executing every action.
The bean is used for defining controls like textfield, Radio button, etc on jsp page.
On submit of this page control goes properly to defined action class, but finds bean object as null in action class. Hence unable to perform futher operations.
Removing interceptors works fine.
Any pointer will be appreciated.
I haven't defined stack for interceptors defined in struts.xml.
After defining below stack in struts.xml its works fine:
<interceptors>
<interceptor-stack name="applicationStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="debugging"/>
<!-- User defined interceptor -->
<interceptor-ref name="contextSecurityInterceptor"/>
</interceptor-stack>

Struts2 input values lost when calling interceptor

i have a problem with Struts2
This is my action configuration, before executing the roleDete in the Action, the interceptor is call, but after this, the values of the input are lost, there is no id to delete, if i remove the interceptor then the id to delete exist, could some one guide me to solve this?
<action name="roleDelete" method="roleDelete" class="com.webapp.role.action.RoleAction">
<interceptor-ref name="validateUser"/>
<result name="input" type="tiles">usertypePage</result>
<result name="success" type="redirect">usertypeForm</result>
</action>
Thanks
It sounds like you've defined a custom validateUser interceptor stack that doesn't include a required Struts 2 interceptor. By default, Struts 2 invokes the following interceptors on every request unless you define your own stack (as you've done):
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
My advice would be to go through the above list and add them back in one at a time until you figure out which you need to properly populate your request variable. You can read more about interceptors in the Struts 2 docs.
<interceptors>
<interceptor name="vendorStoreInterceptor" class="br.org.myapp.actions.interceptors.VendorStoreInterceptor"></interceptor>
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
<interceptor-stack name="mainStack">
<interceptor-ref name="vendorStoreInterceptor"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mainStack"/>
--
Use that. You have to include your interceptor and the defaultStack after (watch the last 'interceptor-stack' with my 'vendorStoreInterceptor' and the 'defaultStack').
That's it!

Resources