• 每日日报2020 12/12


    今天双十二,是个事变的好日子。

    package libraryservlet;

    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 dao.SchoolDaoImpl;
    import entity.School;

    /**
    * Servlet implementation class libraryservlet
    */
    @WebServlet("/libraryservlet")
    public class libraryservlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * @see HttpServlet#HttpServlet()
    */
    public libraryservlet() {
    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());
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");

    String ID=request.getParameter("username");
    HttpSession session=request.getSession();
    session.setAttribute("ID", ID);//存储数据
    request.setAttribute("ID", ID);
    String password=request.getParameter("password");
    String method=request.getParameter("profession");
    SchoolDaoImpl sd=new SchoolDaoImpl();
    if("1".equals(method)) {
    try{
    System.out.println(1);

    if("123456".equals(ID)&&"654321".equals(password)) {
    response.getWriter().println("<script type='text/javascript'> alert('登录成功')</script>");
    request.getRequestDispatcher("manage.jsp").forward(request, response);}
    else {
    response.getWriter().println("<script type='text/javascript'> alert('密码或账号错误')</script>");
    request.getRequestDispatcher("library.jsp").forward(request, response);}
    }catch(Exception e){
    System.out.println("失败");
    e.printStackTrace();
    }
    }

    if("2".equals(method)) {
    try{
    System.out.println(1);

    String stupass=sd.showstuname(ID);


    if(password.equals(stupass)) {
    SchoolDaoImpl sd1=new SchoolDaoImpl();
    java.util.List<School> list=sd1.stushow(ID);

    request.setAttribute("list", list);
    response.getWriter().println("<script type='text/javascript'> alert('登录成功')</script>");
    request.getRequestDispatcher("student.jsp").forward(request, response);}
    else {
    response.getWriter().println("<script type='text/javascript'> alert('账号或密码错误')</script>");
    request.getRequestDispatcher("library.jsp").forward(request, response);}

    }catch(Exception e){
    System.out.println("失败");
    e.printStackTrace();
    }
    }


    }

    /**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    }

    }

  • 相关阅读:
    C++11新特性
    Qt操作xml
    指针和引用的区别
    QT软件主题切换
    常见的临时变量的生成场景
    QQuickWidget+QML设置背景透明
    idea maven Could not transfer artifact
    Java项目启动时执行指定方法的几种方式
    解决bootstrap-table在切换分页后再次查询报错404问题
    bootstrap:表单必填项*标识,及提交前校验
  • 原文地址:https://www.cnblogs.com/song-1/p/14177213.html
Copyright © 2020-2023  润新知