weixin_42510571
2014-10-19 22:37
浏览 263
已采纳

SSH搭建好了之后开始测试Struts的Action 转到自己写的404页面

按照李刚的struts讲义写的action 功能是输入用户名密码之后跳转到另外的jsp页面.但是每次都出来404页面.请问是哪边配置有问题? 如果另外ssh框架也没建好还请指正.以下是代码[code="web.xml"]<?xml version="1.0" encoding="UTF-8"?>
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">

Archetype Created Web Application

<!-- 以下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这个接口,容器启动时会自动执行它实现的方法。 -->

org.springframework.web.context.ContextLoaderListener


contextConfigLocation
classpath:*/ApplicationContext.xml,*/action-Servlet.xml


<!-- 加载spring容器 -->


struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter


struts.action.extendion
action


<!--


struts2
org.apache.struts2.dispatcher.FilterDispatcher

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>-->


action
org.apache.struts.action.ActionServlet

config
/WEB-INF/struts.xml
2

<!-- session超时定义,单位为分钟 -->

120

<!-- 默认首页定义 -->

    <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>


[/code] [code="strut.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">



<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>

</struts>[/code]   [code="ApplicationContext.xml"]<?xml version="1.0" encoding="UTF-8"?>

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&amp;useUnicode=true&amp;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>

[/code] [code="LoginAction"]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;
}


@Override

public String execute() throws Exception{
    System.out.println("AAA");
    if(ms.valid(getUsername(),getPassword())){
        return new String("success");
        }else{
            return "error";}
    }

}
[/code] [code="MyServiceImp"]package calvin.action.test;

public class MyServiceImp implements MyService{
public boolean valid(String username,String pass){
return true;
}

}
[/code] 首页配置就是一个很简单的登陆页面.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • Logic_Luo 2014-10-20 18:47
    已采纳

    把项目上传看看!!!

    打赏 评论
  • zc102520 2014-10-24 22:53

    首页配置就是一个很简单的登陆页面.

    打赏 评论

相关推荐 更多相似问题