日期:2014-05-19  浏览次数:20721 次

struts2_hibernate3.3小例子 不报错 但数据库没反应 小项目在我的资源里面
本帖最后由 yjb8646226 于 2012-11-27 18:46:11 编辑 数据库 sqlserver 数据库名hibernate 建一个person表 5个字段 id username password age registerDate 
熟悉struts2  hibernate的大神帮忙分析下 
项目在我的资源里面可以下载 
------最佳解决方案--------------------
提交代码也OK的!!!
不报错、数据库没反应就是没有添加到数据!!!
你看看有没有打印sql呢?

try {
session.save(person);
tx.commit();
} catch (Exception e) {
if(tx!=null){
tx.rollback();
}
}finally{
HibernateUtil.close(session);
}

Exception e 都没有打印异常呢!!!
e.printStackTrace();
你调试看看走到哪一步、
还真是奇怪呢!

------其他解决方案--------------------
这么懒。。都不贴代码。。。。
------其他解决方案--------------------
commit!!!
LZ提交事务了没有?
------其他解决方案--------------------
index.jsp  
<form action="savePerson.action">
  username:<input type="text" name="username" size="20"><br>
  password:<input type="password" name="password" size="20"><br>
  age:<input type="text" name="age" size="20">
  <input type="submit" value="submit">
  </form>

web.xml
<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>
  </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>
<package name="hibernate" extends="struts-default">
<action name="savePerson" class="com.yjb.action.PersonAction">
<result>/welcome.jsp</result>
</action>
</package>
</struts>    

Person
package com.yjb.model;

import java.sql.Date;

public class Person {
private Integer id;
private String username;
private String password;
private Integer age;
private Date registerDate;
public Integer getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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;
}
public Integer getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Date getRegisterDate() {
return registerDate;
}
public void setRegisterDate(Date registerDate) {