struts2Action配置正确确报404

咕噜咕噜步步 发布于 2017/10/24 16:13
阅读 401
收藏 1

 

通过menu.jsp上的客户列表访问/jsp/customer/list.jsp,但是访问后报错:我检查了好久不知道是哪里错了……

24-Oct-2017 15:44:41.689 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/Library/Tomacat/apache-tomcat-8.5.20/webapps/manager]
24-Oct-2017 15:44:41.718 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/Library/Tomacat/apache-tomcat-8.5.20/webapps/manager] has finished in [28] ms
24-Oct-2017 15:45:21.032 警告 [http-nio-8080-exec-7] org.apache.struts2.dispatcher.Dispatcher.warn Could not find action or result: /ssh_crm/CustomerAction_list
 No result defined for action cn.itcast.web.action.CustomerAction and result error - action - file:/Library/Tomacat/apache-tomcat-8.5.20/webapps/ssh_crm/WEB-INF/classes/struts.xml:30:72
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:273)
    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:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.orm.hibernate5.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:151)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

menu.jsp页面

<TR> 
   <TD class=menuSmall><A class=style2 href="${pageContext.request.contextPath}/CustomerAction_list"
      target=main>- 客户列表</A></TD>
</TR>

CustomerAction.java

package cn.itcast.web.action;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.itcast.domain.Customer;
import cn.itcast.domain.User;
import cn.itcast.service.CustomerService;
import cn.itcast.service.UserService;
import cn.itcast.utils.PageBean;

public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {
   private Customer customer = new Customer();
   
   private CustomerService cs;

   private Integer currentPage;
   private Integer pageSize;
   public String list() throws Exception {
      //封装离线查询对象
      DetachedCriteria dc = DetachedCriteria.forClass(Customer.class);
      //判断并封装参数
      if(StringUtils.isNotBlank(customer.getCust_name())){
         dc.add(Restrictions.like("cust_name", "%"+customer.getCust_name()+"%"));
      }
      
      //1 调用Service查询分页数据(PageBean)
      PageBean pb = cs.getPageBean(dc,currentPage,pageSize);
      //2 将PageBean放入request域,转发到列表页面显示
      ActionContext.getContext().put("pageBean", pb);
      return "list";
   }

   @Override
   public Customer getModel() {
      return customer;
   }

   public void setCs(CustomerService cs) {
      this.cs = cs;
   }

   public Integer getCurrentPage() {
      return currentPage;
   }

   public void setCurrentPage(Integer currentPage) {
      this.currentPage = currentPage;
   }

   public Integer getPageSize() {
      return pageSize;
   }

   public void setPageSize(Integer pageSize) {
      this.pageSize = pageSize;
   }

   
   
}

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
   "http://struts.apache.org/dtds/struts-2.3.dtd">
   
<struts>
   <!-- #  struts.objectFactory = spring  将action的创建交给spring容器   
         struts.objectFactory.spring.autoWire = name spring负责装配Action依赖属性
         -->
   <constant name="struts.objectFactory" value="spring"></constant>

   <package name="crm" namespace="/" extends="struts-default" >
      <global-exception-mappings>
         <exception-mapping result="error" exception="java.lang.RuntimeException"></exception-mapping>
      </global-exception-mappings>
   
      
      <action name="UserAction_*" class="userAction" method="{1}" >
         <result name="toHome" type="redirect" >/index.htm</result>
         <result name="error" >/login.jsp</result>
      </action>
      
      <action name="CustomerAction_*" class="customerAction" method="{1}" >
         <result name="list"  >/jsp/customer/list.jsp</result>
      </action>
   </package>
</struts>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.springframework.org/schema/beans" 
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:aop="http://www.springframework.org/schema/aop" 
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
                     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd 
                     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd ">
   
   <!-- 读取db.properties文件 -->
   <context:property-placeholder location="classpath:db.properties" />
   <!-- 配置c3p0连接池 -->
   <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" >
      <property name="jdbcUrl" value="${jdbc.jdbcUrl}" ></property>
      <property name="driverClass" value="${jdbc.driverClass}" ></property>
      <property name="user" value="${jdbc.user}" ></property>
      <property name="password" value="${jdbc.password}" ></property>
   </bean>
   
   <!-- 核心事务管理器 -->
   <bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager" >
      <property name="sessionFactory" ref="sessionFactory" ></property>
   </bean>
   
   
   <!-- 开启注解事务 -->
   <tx:annotation-driven transaction-manager="transactionManager" />
   
   
   <!-- 在spring配置中放置hibernate配置信息 -->
   <bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" >
      <!-- 将连接池注入到sessionFactory, hibernate会通过连接池获得连接 -->
      <property name="dataSource" ref="dataSource" ></property>
      <!-- 配置hibernate基本信息 -->
      <property name="hibernateProperties">
         <props>
            <!--  必选配置 -->
         <!--   <prop key="hibernate.connection.driver_class" >com.mysql.jdbc.Driver</prop>
            <prop key="hibernate.connection.url" >jdbc:mysql:///crm_32</prop>
            <prop key="hibernate.connection.username" >root</prop>
            <prop key="hibernate.connection.password" >1234</prop> -->
            <prop key="hibernate.dialect" >org.hibernate.dialect.MySQLDialect</prop>
            
            <!--  可选配置 -->
            <prop key="hibernate.show_sql" >true</prop>
            <prop key="hibernate.format_sql" >true</prop>
            <prop key="hibernate.hbm2ddl.auto" >update</prop>
         </props>
      </property>
      <!-- 引入orm元数据,指定orm元数据所在的包路径,spring会自动读取包中的所有配置 -->
      <property name="mappingDirectoryLocations" value="classpath:cn/itcast/domain" ></property>
   </bean>
   
   <!-- action -->
   <!-- 注意:Action对象作用范围一定是多例的.这样才符合struts2架构 -->
   <bean name="userAction" class="cn.itcast.web.action.UserAction" scope="prototype" >
      <property name="userService" ref="userService" ></property>
   </bean>
   <bean name="customerAction" class="cn.itcast.web.action.CustomerAction" scope="prototype" >
      <property name="cs" ref="customerService" ></property>
   </bean>
   <!-- service -->
   <bean name="userService" class="cn.itcast.service.impl.UserServiceImpl" >
      <property name="ud" ref="userDao" ></property>
   </bean>
   <bean name="customerService" class="cn.itcast.service.impl.CustomerServiceImpl" >
      <property name="cd" ref="customerDao" ></property>
   </bean>
   <!-- dao -->
   <bean name="userDao" class="cn.itcast.dao.impl.UserDaoImpl" >
      <!-- 注入sessionFactory -->
      <property name="sessionFactory" ref="sessionFactory" ></property>
   </bean>
   <bean name="customerDao" class="cn.itcast.dao.impl.CustomerDaoImpl" >
      <!-- 注入sessionFactory -->
      <property name="sessionFactory" ref="sessionFactory" ></property>
   </bean>
</beans>
加载中
返回顶部
顶部