错误信息:
applicationContext.xml文件:
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
<!-- 注入映射文件
<property name="mappingResources">
<list>
要修改的地方:注入自己需要的映射文件,可以是多个
<value>com/hkw/pojo/Employee.hbm.xml</value>
</list>
</property> -->
</bean>
<!-- 配置事务管理器 -->
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 定义事务管理器(声明式的事务) -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<!-- 配置事务属性 -->
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Dao</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<!-- 配置DAO -->
<bean id="employeeDao" class="com.hkw.dao.EmployeeDAOImp" scope="singleton">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置注入:service<-DAO,可以多个dao注入同一个service -->
<bean id="employeeService" class="com.hkw.service.EmployeeServiceImp">
<property name="employeeDao" ref="employeeDao"></property>
</bean>
<!-- 配置注入:Action<-service -->
<bean id="employeeAction" class="com.hkw.action.EmployeeAction">
<property name="employeeService" ref="employeeService"></property>
</bean>
</beans>
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">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<!-- <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<package name="employee" extends="struts-default">
<action name="employee" class="com.hkw.action.EmployeeAction">
<result name="add" >/add.jsp</result>
<result name="update" >/update.jsp</result>
<result name="list" >/list.jsp</result>
<result name="relist" type="redirect">/Employee_SSH/employee!list.action</result>
</action>
</package>
</struts>
EmployeeAction.java
public String addSave() {
// int id=Integer.parseInt(UUID.randomUUID().toString());
// employee.setId(id);
System.out.println("开始添加用户");
this.employeeService.save(this.employee);
System.out.println("现在保存增加的employee");
return "relist";
}
add.jsp
<form
action="${pageContext.request.contextPath}/Employee_SSH/employee!addSave.action"
method="post">
<table align="center" border="2" bgcolor="">
<tr>
<td align="center" colspan="2">员工信息录入</td>
</tr>
<tr>
<td>姓名</td>
<td><input type="text" name="employee.name">
</td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" name="employee.age">
</td>
</tr>
<tr>
<td>性别</td>
<td>男<input type="radio" name="employee.sex" value="0" checked>
女<input type="radio" name="employee.sex" value="1"></td>
</tr>
<tr>
<td>电话</td>
<td><input type="text" name="employee.tel">
</td>
</tr>
<tr>
<td>地址</td>
<td><input type="text" name="employee.address">
</td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="提交">
</td>
</tr>
</table>
</form>
表单添加的数据可以添加到数据库。
<result name="relist" type="redirect">/Employee_SSH/employee!list.action</result> 这是要重定向到另外一个命名空间下的action嘛?
如果是那你这里的配置有误!
<result name="reload" type="redirect">
<param name="namespace">XXXXX</param>
<param name="actionName">XXXXX</param>
<param name="method">XXXX</param>
</result>
不是的! 我的每个SSH整合过的项目,每个都是报404的错误!
你知道这是为什么吗?
@博得精彩: 用firebug看看 request的路径是神马样子的?