📄 modifypwdaction.java
字号:
package org.struts2.actions;
import org.hibernate.beans.Login;
import org.hibernate.beans.Student;
import org.hibernate.beans.Teacher;
import org.hibernate.dao.LoginDAO;
import org.hibernate.dao.StudentDAO;
import org.hibernate.dao.TeacherDAO;
import org.struts2.common.PageAction;
import org.struts2.util.Constants;
import com.opensymphony.xwork2.Action;
public class ModifyPwdAction extends PageAction{
/**
*
*/
private static final long serialVersionUID = 1L;
private StudentDAO studentDAO;
private TeacherDAO teacherDAO;
private LoginDAO loginDAO;
private String new_pwd;
public String getNew_pwd() {
return new_pwd;
}
public void setNew_pwd(String new_pwd) {
this.new_pwd = new_pwd;
}
public StudentDAO getStudentDAO() {
return studentDAO;
}
public void setStudentDAO(StudentDAO studentDAO) {
this.studentDAO = studentDAO;
}
public TeacherDAO getTeacherDAO() {
return teacherDAO;
}
public void setTeacherDAO(TeacherDAO teacherDAO) {
this.teacherDAO = teacherDAO;
}
public LoginDAO getLoginDAO() {
return loginDAO;
}
public void setLoginDAO(LoginDAO loginDAO) {
this.loginDAO = loginDAO;
}
public String init(){
clearErrorsAndMessages();
String roleForward = (String)getSession(Constants.USERNAME_ROLE);
return roleForward;
}
public String update(){
clearErrorsAndMessages();
String role = (String)getSession(Constants.USERNAME_ROLE);
String user_id = (String)getSession(Constants.USERNAME_KEY);
if(role.equals("student")){
Student student = this.studentDAO.getStudent(user_id);
student.setStuPwd(new_pwd);
this.studentDAO.updateStudent(student);
}else
if(role.equals("teacher")){
Teacher teacher = this.teacherDAO.getTeacher(user_id);
teacher.setTeacherPwd(new_pwd);
this.teacherDAO.updateTeacher(teacher);
}else
if(role.equals("admin")){
Login login = this.loginDAO.getUser(user_id);
login.setPassword(new_pwd);
this.loginDAO.updateUser(login);
}
return Action.SUCCESS;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -