实在是没有办法了,就是找不到哪里出错了!!!求大神!!!!
本人菜鸟,看张龙老师的视频学习hibernate。
按照视频写的代码,结果只对了一半。
我是用sql server 2005+tomcat 7.0+hibernate 4.10+struts 2.3 搭建的。
代码比较杂,还请各位耐心点。
注册页面代码,register.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"><br>
<input type="submit" value="submit">
</form>
struts.xml 代码
<package name="hibernate" extends="struts-default">
<action name="savePerson" class="com.shengsiyuan.action.PsersonAction" method="savePerson">
<result name="success">/result.jsp</result>
</action>
PsersonAction.java 代码
package com.shengsiyuan.action;
import com.opensymphony.xwork2.ActionSupport;
import com.shengsiyuan.modle.Person;
import com.shengsiyuan.service.PersonService;
import com.shengsiyuan.service.PersonServiceImpl;
public class PsersonAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String username;
private String password;
private int age;
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 int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String savePerson() throws Exception{
Person person=new Person();
person.setUsername(username);
person.setPassword(password);
person.setAge(age);
java.sql.Date registerDate=new java.sql.Date(new java.util.Date().getTime());
person.setRegisterDate(registerDate);
PersonService personService=new PersonServiceImpl();
personService.savePerson(person);
return SUCCESS;
}
}
Person.java 代码
package com.shengsiyuan.modle;
import java.util.Date;
public class Person {
private Integer id;
private String username;
private String password;
private Integer age;
private Date registerDate;
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(Integer age) {
this.age = age;
}
public Date getRegisterDate() {
return registerDate;
}
public void setRegisterDate(Date registerDate) {
this.registerDate = registerDate;
}
PersonServiceImpl.java 代码
package com.shengsiyuan.service;
import com.shengsiyuan.dao.PersonDAO;
import com.shengsiyuan.modle.Person;
import com.shengsiyuan.dao.PersonDAOImpl;
public class PersonServiceImpl implements PersonService
{
@Override
public void savePerson(Person person)
{