问题描述
按照李刚的struts讲义写的action 功能是输入用户名密码之后跳转到另外的jsp页面.但是每次都出来404页面.请问是哪边配置有问题? 如果另外ssh框架也没建好还请指正.以下是代码<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"> <display-name>Archetype Created Web Application</display-name> <!-- 以下3项参数与log4j的配置相关 --> <listener><listener-class>org.springframework.web.util.Log4jConfigListener</listener-class></listener><context-param><param-name>log4jConfigLocation</param-name><param-value>/WEB-INF/log4j.properties</param-value></context-param><context-param><param-name>log4jRefreshInterval</param-name><param-value>60000</param-value></context-param> <!-- 默认情况下,会加载WEB-INF/applicationContext.xml这个文件,我们可以通过配置 contextConfigLocation参数改变配置文件的路径 --> <!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔 此参数用于后面的Spring-Context loader --><!-- 使容器启动时,自动加载applicationContext配置,因为它实现了ServletContextListener这个接口,容器启动时会自动执行它实现的方法。 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:*/ApplicationContext.xml,*/action-Servlet.xml</param-value></context-param> <!-- 加载spring容器 --><!-- 整合struts 加入中心拦截器 --><filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> <init-param> <param-name>struts.action.extendion</param-name> <param-value>action</param-value> </init-param> </filter> <!-- <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>/*</url-pattern> </filter-mapping>--> <!-- Struts --><servlet><servlet-name>action</servlet-name><servlet-class>org.apache.struts.action.ActionServlet</servlet-class><init-param><param-name>config</param-name><param-value>/WEB-INF/struts.xml</param-value></init-param><load-on-startup>2</load-on-startup></servlet> <!-- session超时定义,单位为分钟 --><session-config><session-timeout>120</session-timeout></session-config><!-- 默认首页定义 --><welcome-file-list><welcome-file>login2.jsp</welcome-file></welcome-file-list><!-- Error Page定义 --><error-page> <exception-type>java.lang.Throwable</exception-type> <location>/commons/error.jsp</location> </error-page> <error-page><error-code>500</error-code><location>/commons/error.jsp</location></error-page><error-page><error-code>404</error-code><location>/commons/404.jsp</location></error-page><error-page><error-code>403</error-code><location>/commons/403.jsp</location></error-page> </web-app> <?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.devMode" value="true"/> <constant name="struts.objectFactory" value="spring" ></constant><package name="calvin" extends="struts-default"> <action name="login" class="/loginAction"> <result name="error">index.jsp</result> <result name="success">/pages/index.jsp</result> </action></package> </struts> <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- Spring容器配置文件 --> <!-- 告诉spring hibernate文件的位置 然后加载 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/policemanagement?autoReconnect=true&useUnicode=true&characterEncoding=utf-8"/> <property name="username" value="root"/> <property name="password" value="rooot"/> <property name="maxActive" value="100"/> <property name="maxIdle" value="30"/> <property name="maxWait" value="1000"/> <property name="defaultAutoCommit" value="true"/> <property name="removeAbandoned" value="true"/> <property name="removeAbandonedTimeout" value="60"/> <property name="logAbandoned" value="true"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mappingResources" > <list> <value>calvin/po/pojo/hbm/arrestedPerson.hbm.xml</value> <value>calvin/po/pojo/hbm/caseRegisted.hbm.xml</value> <value>calvin/po/pojo/hbm/caseThread.hbm.xml</value> <value>calvin/po/pojo/hbm/caseVictim.hbm.xml</value> <value>calvin/po/pojo/hbm/policeOfficer.hbm.xml</value> <value>calvin/po/pojo/hbm/victimOffice.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hbm2ddl.auto">create</prop> </props> </property> </bean> <!-- 为hibernte配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- daoContext 配置原因 所以放在这边 --> <bean id="dao" class="calvin.dao.imp.BaseDAOHibernate"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="policeOfficerDAO" class="calvin.dao.imp.PoliceOfficerImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="arrestedPersonDAO" class="calvin.dao.imp.ArrestedPersonImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="caseRegisteredDAO" class="calvin.dao.imp.CaseRegisteredImp"><property name="sessionFactory" ref="sessionFactory" /></bean><bean id="caseThreadDAO" class="calvin.dao.imp.CaseThreadImp"><property name="sessionFactory" ref="sessionFactory" /></bean><bean id="caseVictimDAO" class="calvin.dao.imp.CaseVictimImp"><property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="victimOfficeDAO" class="calvin.dao.imp.VictimOfficeImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <!-- ENd --> <!-- IOC 注入机制 --> <!-- 定义事务模板类 --> <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <!-- 注入事务管理器 --> <property name="transactionManager" ref="transactionManager"/> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property></bean> <!-- 配置具体业务逻辑层组件的事物代理 --> <bean id="manager" parent="txProxyTemplate"> <property name="target"> <bean class="calvin.service.BaseManager"> <property name="dao" ref="dao"/> </bean> </property> </bean> <!-- 配置具体的业务逻辑组件额事务代理 --> <!-- 配置业务逻辑组件的事务代理,使用了bean 的继承 --> <!-- 配置所需要的dao组件!!!即这里用的是dao的名字 --> <bean id="facadeManager" parent="txProxyTemplate"> <!-- 配置事务代理时,指定代理的目标,此处的目标是嵌套bean--> <property name="target"> <!-- 嵌套bean无须使用 id属性--> <bean class="calvin.service.imp.FacadeManagerImp"> <!-- 为业务逻辑组件注入DAO组件 --> <property name="victimOfficeDAO" ref="victimOfficeDAO"/> <property name="policeOfficerDAO" ref="policeOfficerDAO"/> <property name="caseVictimDAO" ref="caseVictimDAO"/> <property name="caseThreadDAO" ref="caseThreadDAO"/> <property name="caseRegisteredDAO" ref="caseRegisteredDAO"/> <property name="arrestedPersonDAO" ref="arrestedPersonDAO"/> </bean></property> </bean> <!-- action --> <bean id="myService" class="calvin.action.test.MyServiceImp"/> <bean name="/loginAction" class="calvin.action.LoginAction" scope="prototype"> <property name="ms" ref="myService"/> </bean> </beans> package calvin.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.junit.Test;import calvin.action.baseAction.BaseAction;import calvin.action.test.MyService;import calvin.po.pojo.PoliceOfficer;public class LoginAction extends BaseAction{private String username;private String password;private MyService ms;public MyService getMs() {return ms;}public void setMs(MyService ms) {this.ms = ms;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}@Overridepublic String execute() throws Exception{System.out.println("AAA");if(ms.valid(getUsername(),getPassword())){return new String("success");}else{return "error";}}} package calvin.action.test;public class MyServiceImp implements MyService{public boolean valid(String username,String pass){return true;}} 首页配置就是一个很简单的登陆页面.
解决方案
把项目上传看看!!!
解决方案二:
首页配置就是一个很简单的登陆页面.