package com.yetang.web;
import com.yetang.pojo.User01;
import com.yetang.pojo.User02;
import com.yetang.service.UserService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Objects;
@WebServlet("/Login")
public class Login extends HttpServlet {
private UserService service = new UserService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=UTF-8");
String data1 = request.getParameter("data1");
String data2 = request.getParameter("data2");
String temp = request.getParameter("temp");
PrintWriter out = response.getWriter();
request.setAttribute("data1",data1);
if(Objects.equals(temp, "4")){
if(Objects.equals(data1, "admin") && Objects.equals(data2, "123456"))
request.getRequestDispatcher("/A.jsp").forward(request,response);
else {
out.write("<script>");
out.write("alert('登录失败!用户账号或密码错误!');");
out.write("window.location.href='Login.jsp'");
out.write("</script>");
out.close();
}
}else if(Objects.equals(temp, "0")|| Objects.equals(temp, "1") || Objects.equals(temp, "2")){
User02 user02 = service.select2B1(data1);
if(user02==null){
out.write("<script>");
out.write("alert('登录失败!用户账号或密码错误!');");
out.write("window.location.href='Login.jsp'");
out.write("</script>");
out.close();
}else if(Objects.equals(user02.getData6(), data2)){
request.setAttribute("user02",user02);
request.getRequestDispatcher("/T.jsp").forward(request,response);
}else {
out.write("<script>");
out.write("alert('登录失败!用户账号或密码错误!');");
out.write("window.location.href='Login.jsp'");
out.write("</script>");
out.close();
}
}else {
User01 user01 = service.select1B1(data1);
if(user01==null){
out.write("<script>");
out.write("alert('登录失败!用户账号或密码错误!');");
out.write("window.location.href='Login.jsp'");
out.write("</script>");
out.close();
}else if(Objects.equals(user01.getData9(), data2)&& Objects.equals(user01.getData8(), "1")){
request.setAttribute("user01",user01);
request.getRequestDispatcher("/S.jsp").forward(request,response);
}else {
out.write("<script>");
out.write("alert('登录失败!用户账号或密码错误!');");
out.write("window.location.href='Login.jsp'");
out.write("</script>");
out.close();
}
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
package com.yetang.web;
import com.yetang.pojo.User01;
import com.yetang.service.UserService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebServlet("/Preset")
public class Preset extends HttpServlet {
private UserService service = new UserService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=UTF-8");
String data1 = request.getParameter("data1");
User01 user01 = service.select1B1(data1);
user01.setData9("123456");
service.update1B1(user01);
request.getRequestDispatcher("/A.jsp").forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}