package com.oe.action;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import com.oe.po.Student;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
private int studentId;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private String password;
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String login(){
SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sf.getCurrentSession();
session.beginTransaction();
String hql = "from Student s where s.studentId=? and s.password=?";
System.out.println(hql);
List list = (List)session.createQuery(hql).setInteger(0, studentId).setString(1, password).list();
session.getTransaction().commit();
if(list.isEmpty()){
this.addFieldError("Error", "登录失败 ");
return ERROR;
}
return SUCCESS;
}
public String register(){
SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sf.getCurrentSession();
session.beginTransaction();
String hql = "from Student s where s.studentId=?";
List list = (List)session.createQuery(hql).setInteger(0, studentId).list();
if(list.isEmpty()){
Student student = new Student();
student.setStudentId(studentId);
student.setName(name);
student.setPassword(password);
session.save(student);
session.getTransaction().commit();
return SUCCESS;
}
else{
this.addFieldError("Error", "注册失败!");
return ERROR;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
OE.rar (36个子文件)
OE
.project 1KB
SQL
oe.sql 174B
.settings
.jsdtscope 500B
org.eclipse.jdt.core.prefs 330B
com.genuitec.eclipse.j2eedt.core.prefs 1KB
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 289B
WebRoot
login.jsp 1KB
WEB-INF
web.xml 692B
lib
classes
com
oe
action
UserAction.class 3KB
po
examQuestion.class 862B
question.class 1KB
exam.class 909B
answer.class 927B
subject.class 730B
admin.class 897B
selects.class 903B
studentAnswer.class 1KB
type.class 712B
Student.class 1KB
score.class 1KB
struts.xml 545B
testStudent.class 1KB
hibernate.cfg.xml 1KB
META-INF
MANIFEST.MF 36B
register.jsp 1KB
error.jsp 1001B
main.jsp 836B
admin
index.jsp 831B
.myeclipse
src
com
oe
action
UserAction.java 2KB
po
Student.java 793B
struts.xml 545B
hibernate.cfg.xml 1KB
com.oe.test
testStudent.java 525B
.classpath 735B
共 36 条
- 1
t519487760
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页