package com.neuedu.javaweb.chap02;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.neuedu.pojo.User;
import com.neuedu.servlet.IUserservlet;
import com.neuedu.servlet.impl.UserservletImpl;
/**
* Servlet implementation class UpdatePwdServlet
*/
@WebServlet("/updatePwdServlet")
public class UpdatePwdServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public UpdatePwdServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at:
// ").append(request.getContextPath());
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charest=UTF-8");
String id = request.getParameter("id");
String pwd = request.getParameter("password");
String re_pwd = request.getParameter("re_pwd");
IUserservlet login=new UserservletImpl();
User user = new User();
user.setId(Integer.parseInt(id));
user.setPassword(pwd);
String result;
int i = login.updatePwdUser(user);
if (i > 0) {
if (pwd.equals(re_pwd)) {
result = "修改成功";
HttpSession session = request.getSession();
User sessUser = (User) session.getAttribute("user");
sessUser.setPassword(pwd);
session.setAttribute("user", sessUser);
request.setAttribute("result", result);
} else {
result = "修改失败";
request.setAttribute("result", result);
}
request.getRequestDispatcher("/user/UpdatePwd.jsp").forward(request, response);
}
}
}
网友评论