我在java web项目中使用struts 2。我想将Action成功重定向到另一个jsp但它不起作用。 这是我的代码:
public class ConfigurerDureeStockageAction extends ActionSupport implements ServletRequestAware{
private final static Logger logger = Logger.getLogger(ConfigurerDureeStockageAction.class);
private static final long serialVersionUID = 1L;
private HttpServletRequest request;
public void setServletRequest(HttpServletRequest request){
this.request = request;
}
public String execute()throws Exception{
logger.debub("Execute SUCCESS");
return SUCCESS;
}
public String savePeriod(){
logger.debub("savePeriod SUCCESS");
return SUCCESS;
}
}
我的struts.xml是
<action name="AdminIndex" class="fr.si2m.occ.web.actions.admin.AdminIndexAction"
method="execute">
<result name="success">adminIndex.jsp</result>
</action>
<action name="ConfigurerDureeStockageSave" class="fr.si2m.occ.web.actions.admin.ConfigurerDureeStockageAction"
method="savePeriod">
<result name="success">adminIndex.jsp</result>
</action>
我试试这个
<action name="ConfigurerDureeStockageSave" class="fr.si2m.occ.web.actions.admin.ConfigurerDureeStockageAction"
method="savePeriod">
<result name="success" type="redirect">
<param name="location">adminIndex.jsp</param >
</result>
</action>
和这个
<action name="ConfigurerDureeStockageSave" class="fr.si2m.occ.web.actions.admin.ConfigurerDureeStockageAction"
method="savePeriod">
<result name="success" type="redirect">
<param name="actionName">AdminIndex</param>
</result>
</action>
最后一个配置给出了以下错误:
Caught OgnlException while setting property 'actionName' on type 'org.apache.struts2.dispatcher.ServletRedirectResult'.
Caught OgnlException while setting property 'actionName' on type 'org.apache.struts2.dispatcher.ServletRedirectResult'. - Class: ognl.ObjectPropertyAccessor
File: ObjectPropertyAccessor.java
Method: setProperty
Line: 166 - ognl/ObjectPropertyAccessor.java:166:-1
at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:430)
at com.opensymphony.xwork2.ognl.OgnlUtil.setProperty(OgnlUtil.java:160)
at com.opensymphony.xwork2.ognl.OgnlReflectionProvider.setProperty(OgnlReflectionProvider.java:91)
at com.opensymphony.xwork2.ObjectFactory.buildResult(ObjectFactory.java:233)
at com.opensymphony.xwork2.DefaultActionInvocation.createResult(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:368)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
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:249)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
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:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
Caused by: ognl.NoSuchPropertyException: org.apache.struts2.dispatcher.ServletRedirectResult.actionName
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:166)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2315)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlU
12:12:06,608 INFO [STDOUT] til.java:217)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:209)
at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:423)
... 72 more
一直不工作。
我的问题是:
1-为什么配置<result name="success">adminIndex.jsp</result>
不起作用?
2-为什么配置
<result name="success" type="redirect">
<param name="location">adminIndex.jsp</param >
</result>
不起作用? 3-为什么我收到配置错误
<result name="success" type="redirect">
<param name="actionName">AdminIndex</param>
</result>
? AdminIndex操作在struts.xml中声明。我很迷惑。 有人可以帮我吗?
答案 0 :(得分:1)
你的问题是你不应该使用属性<param name="actionName">AdminIndex</param>
,这是解决方案:
<result name="success" type="redirectAction">
<param name="actionName">AdminIndex</param>
</result>
关于文档Struts2 Redirect Action Result Type,您应该使用redirectAction
代替redirect
回答你的问题:
请提供更多详细信息。
试试这个(假设您的命名空间配置正确):
<action name="ConfigurerDureeStockageSave" class="fr.si2m.occ.web.actions.admin.ConfigurerDureeStockageAction" method="savePeriod">
<result name="success" type="redirect">
<param name="location">adminIndex.action</param >
</result>
</action>
或
<action name="ConfigurerDureeStockageSave" class="fr.si2m.occ.web.actions.admin.ConfigurerDureeStockageAction" method="savePeriod">
<result name="success">
<param name="location">adminIndex.jsp</param >
</result>
</action>
因为结果类型redirect
没有属性actionName
,所以您应该使用具有此属性的redirectAction
结果类型