自己搭了个SSh框架。在地址栏输入http://localhost:7080/mobilBuyTicket/twe/mobilBooking!test.action测试数据测持久化。打断点能访问到test方法。但是无法跳转到result页面web.xml中
 <!-- Struts2拦截器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
 <init-param>
<param-name>actionPackages</param-name>
<param-value>main.action</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>struts.xml中:
          <action name="input" class="OutputAction" method="actionMethod">
    <result name="output">/success.jsp</result>
</action>action中方法         public String test(){
//this.mobilBookingService.creat();
return "out";
}
我把业务代码都注释掉了,就一个跳转,就跳不过去。提示
No result defined for action main.action.MobilBookingAction and result out
我把斜杠去掉<result name="output">success.jsp</result>还是报错,变为<result name="out" type="redirect">/success.jsp</result>也报错,我的success.jsp页面就是建在webRoot下的
请问是什么问题啊

解决方案 »

  1.   

     public String test(){
    //this.mobilBookingService.creat();
    return "out";
    }
    从这里可以看去 result属性是 out;
    所以struts配置文件应该这样
    <result name="out">webRoot/success.jsp</result>
      

  2.   

    你的actionMethod方法返回的string 的值决定你的跳转!
    return “output” 和 <result name="output">/success.jsp</result>
    的name="output"中的值是一致的!
      

  3.   

    加了webRoot也不行,还是报那个错
      

  4.   

    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>把这些换成<filter-mapping>
       <filter-name>struts2</filter-name>
       <url-pattern>/*</url-pattern>
       </filter-mapping> 试试···路径的问题,仔细找找···
      

  5.   

    一般写成上面那样 就可以截取到浏览器所有的请求, 简单些
    你的Struts的配置文件 class 应该是action的路径名称!
      

  6.   


    我上面黏贴错了。我的struts.xml配置文件中是
    <package name="strut3" namespace="/twe" extends="struts-default" >
      <action name="mobilBooking" class="main.action.MobilBookingAction" method="test">
        <result name="out2" type="redirect">/success.jsp</result>
      </action>
    </package>能访问到action。就是跳转不到jsp
      

  7.   

    把这个“web.xml中
     <!-- Struts2拦截器 -->
    <init-param>
    <param-name>actionPackages</param-name>
    <param-value>main.action</param-value>
    </init-param>
    ”删掉,试试吧
     
      

  8.   

    我觉得也是拦截器actionPackages的问题
      

  9.   

    <action name="mobilBooking" class="main.action.MobilBookingAction" method="test">
    在你的action类中 有这个test()方法?
      

  10.   

    No result defined for action main.action.MobilBookingAction and result out!!!
    没有out对应的result视图啊 你检查下  result中 的name'写对了没 
      

  11.   

    我把上面的删掉了。tomcat启动报错Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).我又把struts2-codebehind-plugin-2.1.6.jar包删掉后tomcat启动正常
    可这次连action都访问不到了。报错
    2012-05-05 08:48:33,765 - org.apache.struts2.dispatcher.Dispatcher -33656 [http-7080-1] WARN    - Could not find action or result
    There is no Action mapped for action name mobilBooking. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
    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:127)
    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:298)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1600)
    at java.lang.Thread.run(Unknown Source)
    愁死我了,是不是jar包有问题啊。
      

  12.   

    改成如下,struts 2的不同版本,配置是有差异的,另外,你的package命名不规范。<filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
     <init-param>
     <param-name>actionPackages</param-name>
     <param-value>main.action</param-value>
     </init-param>
     </filter>
     <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*.action</url-pattern> 拦截.action 方法
     </filter-mapping>
    <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*.jsp</url-pattern> 拦截.action 方法
     </filter-mapping>
      

  13.   

    把过滤器
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.jsp</url-pattern>
    换成
    <filter-name>struts2</filter-name>
     <url-pattern>/*</url-pattern>
    struts.xml的配置不正确
     <action name="input" class="OutputAction" method="actionMethod">
    <result name="output">/success.jsp</result>
    </action>
    其中的class应该加上OutputAction所在的包名,且要保证OutputAction中有actionMethod方法,不然无法实现跳转
    根据你所说的
    action中方法 
    public String test(){
    //this.mobilBookingService.creat();
    return "out";
    }
    上面的struts.xml应该这样配置(class要加上包名!)
    <action name="input" class="包名.OutputAction" method="test">
    <result name="out">/success.jsp</result>
    </action>还有一点是,你所写的jsp页面的action=“”是否写正确。
    比如:
    index.jsp
    <form action="aa/test">
    struts.xml
    <package name="default" namespace="/aa"extends="struts-default">
    <action name="test" class="包名.OutputAction" method="test">
    <result name="out">/success.jsp</result>
    </action>希望能帮到楼主!
      

  14.   


    我试过这个新的默认拦截器,还是不行。我都把struts2由2.1.8降为2.1.6了,换了好几个jar包,还是不行。真是晕了
      

  15.   


    2.1.3之后,就必须用StrutsPrepareAndExecuteFilter这个class了。
      

  16.   

    1、你是否有结合spring?将struts的action交由spring托管?
    2、如果1没有,则struts.xml中的配置,struts.xml中:
      <action name="input" class="OutputAction" method="actionMethod">
    <result name="output">/success.jsp</result>
    </action>不对,class要写全路径。
    并且,method也不对,也给成你的test
      

  17.   


    我发帖时黏贴错了,又没有权限修改,请看6楼。我是交给spring了。写了<constant name="struts.objectFactory" value="spring" />了,不知道哪里错了。晕啊
      

  18.   


    6楼没有<constant name="struts.objectFactory" value="spring" />这句。我怀疑你struts 2 + spring配置的不对,另外,既然你交由spring管理bean了,你的application.xml中,
    OutputAction是如何宣告的?另外,最好将这个名字改为output。
    在struts.xml中,改为<action name="input" class="output" method="test">
    <result name="output">/success.jsp</result>
    </action>
      

  19.   

    有点小进展,我发现了个错误。我的success.jsp建文件名时前面多了个空格,删掉后。可以进入action的断点了,但是跳转不到jsp。报错No result defined for action main.action.MobilBookingAction and result out2。我的struts.xml如下
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>
         <constant name="struts.objectFactory" value="spring" />
           <package name="strut2" extends="struts-default" >
              <interceptors>
                <interceptor-stack name="testStack">
                    <interceptor-ref name="defaultStack"></interceptor-ref>
                </interceptor-stack>
              </interceptors>
              <default-interceptor-ref name="testStack"></default-interceptor-ref>
           </package>

           <package name="mobil"  namespace="/twe" extends="struts-default" >
              <action name="mobilBooking" class="mobilBookingAction" method="test">
                <result name="out2">/success.jsp</result>
              </action>
           </package>
    </struts>
    把mobil包的继承extends改为上面的包strut2的话,连action断点也进不去。报以前的错换种方法,加入struts2-codebehind-plugin-2.1.6.jar包。删掉struts.xml中mobil包的配置action改为@Namespace("/twe")
    @Results( { @Result(name = "out2", value = "/success.jsp")
         })
    public class MobilBookingAction extends ActionSupport{        private static final long serialVersionUID = 1L;
            private MobilBookingService mobilBookingService;        public MobilBookingService getMobilBookingService() {
               return mobilBookingService;
            }        public void setMobilBookingService(MobilBookingService mobilBookingService) {
               this.mobilBookingService = mobilBookingService;
            }

            public String test(){
               //this.mobilBookingService.creat();
               断点处return "out2";
            }
    }  这种注解方法就可以跳转成功。可用xml配置就找不到视图。求高手指点!
      

  20.   


    还是配置的问题呀。是相关jar的问题。你记得吗。你的web.xml中,
    <init-param>
    <param-name>actionPackages</param-name>
    <param-value>main.action</param-value>
    </init-param>这句话是什么作用吗?
    你既然有这句话,说明你的action就是希望通过注解来宣告。
      

  21.   


    感谢昨日凡阳的指导,actionPackages原来是注解的配置,我还以为是过滤器的配置呢。可是我删掉这段后。又把struts2-codebehind-plugin-2.1.6.jar包删掉(否则启动报错)。再运行连action断点都进不去了,这是为什么啊。还是哪里配置不对啊。
    我的web.xml配置如下<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      
      <!-- 添加spring监听,加载spring容器 -->
      <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        
      <!-- 添加spring上下文使用的配置文件 -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
          classpath:resource/applicationContext.xml
    </param-value>
    </context-param>
      
      <!-- Struts2拦截器 -->
    <filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
     </filter>
     <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*.action</url-pattern> 
     </filter-mapping>
    <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*.jsp</url-pattern> 
     </filter-mapping>
    </web-app>srping配置如下<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:flex="http://www.springframework.org/schema/flex"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
    default-autowire="byName"> <context:property-placeholder location="classpath:resource/jdbc.properties"/>

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"    destroy-method="close">
    <property name="driverClass"><value>${jdbc.driverClassName}</value></property>
    <property name="jdbcUrl"><value>${jdbc.url}</value></property>               
    <property name="user"><value>${jdbc.username}</value></property>
    <property name="password"><value>${jdbc.password}</value></property>
    <property name="minPoolSize"><value>10</value></property>
    <property name="maxPoolSize"><value>100</value></property>
    <property name="maxIdleTime"><value>1800</value></property>
    <property name="acquireIncrement"><value>2</value></property>
    <property name="maxStatements"><value>0</value></property>
    <property name="initialPoolSize"><value>10</value></property>
    <property name="idleConnectionTestPeriod"><value>1000</value></property>
    <property name="acquireRetryAttempts"><value>30</value></property>
    <property name="acquireRetryDelay"><value>100</value></property>
    <property name="breakAfterAcquireFailure"><value>false</value></property>
    <property name="testConnectionOnCheckout"><value>false</value></property>
    </bean>

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <!--  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> -->
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:resource/hibernate.cfg.xml" />
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
    <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
    <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
    <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
    <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
    <prop key="hibernate.format_sql">false</prop>
    </props>
    </property>
    </bean> <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
        
        <!-- dao注入 -->
    <bean id="merchantDao" class="main.dao.imp.MerchantDaoImp"/>
    <!-- service注入 -->
    <bean id="mobilBookingService" class="main.service.imp.MobilBookingServiceImp"/>
    <!-- action注入 -->  
    <bean id="mobilBookingAction" class="main.action.MobilBookingAction"/>
    </beans>
    请高手指教
      

  22.   

    你返回的字符串是out但是咋配置文件中配置的是output
      

  23.   

    struts 2是什么版本,2.1.3之后,要用StrutsPrepareAndExecuteFilter。
      

  24.   

    struts是2.1.8后来改了2.1.6换成org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter也不行。
    算了,先用注解做吧。结贴了,散分。第一次提问,体验下怎么散分,呵呵。