jsp数据提交页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:form action="userAction" namespace="/user" method="post">
<table width="200" border="1">
<tr>
<td>name</td>
<td><s:textfield name="user.name"/></td>
</tr>
<tr>
<td>password</td>
<td><s:textfield name="user.pwd"/></td>
</tr>
<tr>
<td colspan="2"><s:submit value="submit"/></td>
</tr>
</table>
</s:form>
</body>
</html>
控制台报错:
17:41:16,129 ERROR ParametersInterceptor:34 - Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'user.name' on 'class $Proxy10: Error setting expression 'user.name' with value '[Ljava.lang.String;@12dcbd'
17:41:16,180 ERROR ParametersInterceptor:34 - Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'user.pwd' on 'class $Proxy10: Error setting expression 'user.pwd' with value '[Ljava.lang.String;@1cbcf19'
um----------------------:null
dao的实现类:
public class S3Impl implements UserDao{
private SessionFactory sessionFactory = null;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
public boolean create(UserModel um) {
Session session = sessionFactory.getCurrentSession();
session.save(um);
return true;
}
}
页面报错:
Struts Problem Report
Struts has detected an unhandled exception:
Messages: attempt to create saveOrUpdate event with null entity
File: org/hibernate/event/spi/SaveOrUpdateEvent.java
Line number: 62
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.ui.theme" value="simple"></constant>
<constant name="struts.objectFactory" value="spring"/>
<package name="user" namespace="/user" extends="struts-default">
<action name="userAction" class="userAction">
<result name="SUCCESS">/list.jsp</result>
<result name="ERROR">/error.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" 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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">
<bean name="userAction" class="cn.xiaoxing.s3.action.UserAction" scope="prototype">
<property name="userEbi" ref="userEbi"></property>
</bean>
<bean name="userEbi" class="cn.xiaoxing.s3.business.ebo.UserEbo">
<property name="userDao" ref="S3Impl"></property>
</bean>
<bean name="S3Impl" class="cn.xiaoxing.s3.dao.impl.S3Impl">
<!-- ref="dbConfig":表示要注意哪个对象 -->
<property name="sessionFactory" ref="hbConfig"></property>
</bean>
<!-- 在Spring的application context中创建 SessionFactory -->
<bean id="hbConfig" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 把连接数据信息注入到dbConfig -->
<property name="dataSource" ref="dataSource"></property>
<!-- 资源注册 -->
<property name="mappingResources">
<list>
<value>cn/xiaoxing/s3/vo/UserModel.hbm.xml</value>
</list>
</property>
<!-- 可选配置 -->
<property name="hibernateProperties">
<props>
<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.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
</props>
</property>
</bean>
<!-- 配置数据源 -->
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8</value>
</property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
</bean>
<!-- 第二种方法:spring事务配置,拟管理类上需要加上@transactional支持
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
-->
<!-- 第一种方法:spring事务配置 -->
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="hbConfig"></property>
</bean>
<!--事务切入点配置-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!--配置切入点与被应用类关联-->
<aop:config>
<aop:pointcut id="myPointCut" expression="execution(* cn.xiaoxing.s3..*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="myPointCut"/>
</aop:config>
</beans>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。