📄 checkpwd.java
字号:
package org.chooseClass.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.chooseClass.database.DBConnect;
import org.hibernate.dao.LoginDAO;
import org.hibernate.dao.StudentDAO;
import org.hibernate.dao.TeacherDAO;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.struts2.util.Constants;
public class CheckPwd extends HttpServlet {
/**
* Constructor of the object.
*/
public CheckPwd() {
super();
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml");
PrintWriter out = response.getWriter();
String old_pwd = request.getParameter("old_pwd");
String role = (String)request.getSession().getAttribute(Constants.USERNAME_ROLE);
String user_id = (String)request.getSession().getAttribute(Constants.USERNAME_KEY);
boolean isValid = false;
WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
try {
if(role.equals("student")){
StudentDAO studentDAO = (StudentDAO) wac.getBean("studentDAO");
isValid = studentDAO.isValid(user_id, old_pwd);
}else
if(role.equals("teacher")){
TeacherDAO teacherDAO = (TeacherDAO) wac.getBean("teacherDAO");
isValid = teacherDAO.isValid(user_id, old_pwd);
}else
if(role.equals("admin")){
LoginDAO loginDAO = (LoginDAO) wac.getBean("loginDAO");
isValid = loginDAO.isValid(user_id, old_pwd);
}
if(isValid){
out.print("密码正确!请继续输入新密码!");
}
else{
out.print("密码错误!请重新输入密码!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -