2012-09-19 99 views
0

我在我的java web項目中使用struts 2。我想將Action成功重定向到另一個jsp,但它不起作用。 這裏是我的代碼:Struts 2重定向到另一個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> 

這最後的配置給我的跟隨錯誤r:

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

我已更新。我已經忘記了這段代碼 \t \t \t AdminIndex – Pracede

回答

1

你的問題,你不應該使用屬性<param name="actionName">AdminIndex</param>,這裏是解決方案:

<result name="success" type="redirectAction"> 
    <param name="actionName">AdminIndex</param> 
</result> 

關於向DOC Struts2 Redirect Action Result Type,你應該使用redirectAction代替redirect

回答您的問題:

  1. 請給我們更多的細節。

  2. 試試這個(假設你的命名空間的配置是正確的):

    <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> 
    
  3. 因爲結果類型redirect沒有財產actionName,你應該使用redirectAction結果類型,它有這個屬性

+0

我嘗試了2和3的建議,但它不起作用!有人可以給我un重定向的例子,這有效嗎? – Pracede

+0

你能告訴我,如果我的代碼不起作用,錯誤是什麼。是404還是其他的東西。 – Jaiwo99

+0

我嘗試了所有的解決方案。這是行不通的。謝謝你的幫助 – Pracede