zoukankan      html  css  js  c++  java
  • JAVA日报

    javaweb(servlet)

    package servlet;
    import java.io.IOException;
    import java.sql.SQLException;
    import java.util.ArrayList;
    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 bean.*;
    import dao.*;
    @WebServlet("/UserServlet")
    public class UserServlet extends HttpServlet{
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html; charset=utf-8");
    String method = request.getParameter("method");
    if ("add".equals(method)){
    try {
    add(request,response);
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (ServletException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }else if("del".equals(method)){
    try {
    del(request,response);
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (ServletException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }else if("gai".equals(method)){
    try {
    gai(request,response);
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (ServletException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    else if("enter".equals(method)){
    try {
    enter(request,response);
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (ServletException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    }
    }
    protected void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException {
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html; charset=utf-8");
    String UserID=request.getParameter("UserID");
    String UserName=request.getParameter("UserName");
    String sex=request.getParameter("sex");
    String idNumber=request.getParameter("idNumber");
    String Phone=request.getParameter("Phone");
    String User=request.getParameter("User");
    String Password=request.getParameter("Password");
    User user=new User(UserID,UserName,sex,idNumber,Phone,User,Password);
    UserDao userdao=new UserDao();
    userdao.addC(user);
    request.getRequestDispatcher("enter.jsp").forward(request,response);
    }
    protected void del(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException {
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html; charset=utf-8");
    String UserID=request.getParameter("UserID");
    System.out.println(UserID);
    UserDao userdao=new UserDao();
    userdao.delC(UserID);
    request.getRequestDispatcher("user.jsp").forward(request,response);
    }
    protected void gai(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException {
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html; charset=utf-8");
    String role=request.getParameter("role");
    String id1=request.getParameter("id1");
    String id3=request.getParameter("UserID");
    System.out.println(id3);
    UserDao userdao=new UserDao();
    userdao.gaiC(role,id1,id3);
    request.getRequestDispatcher("user.jsp").forward(request,response);
    }
    protected void enter(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException {
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html; charset=utf-8");
    String role=request.getParameter("role");
    String id=request.getParameter("UserID");
    String password=request.getParameter("Password");
    ArrayList<User> users=new UserDao().getAlluserinfos();
    int temp=0;
    for(User user:users) {
    if(user.get("UserID").equals(id)) {
    temp++;
    if(user.get("Password").equals(password)) {
    request.setAttribute("message", "密码正确");
    }else {
    request.setAttribute("message", "密码错误");
    }
    }
    }
    if(temp==0) {
    request.setAttribute("message", "没有该ID");
    }
    request.getRequestDispatcher("enter.jsp").forward(request,response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request, response);
    }
    }

  • 相关阅读:
    openstack 之Queen版本安装完成创建实例状态报错为ERROR
    重启nova-scheduler服务,报错Login was refused using authentication mechanism AMQPLAIN
    Failed to contact the endpoint at http://controller:35357/ for discovery. Fallback to using that endpoint as the base url.
    在centos系统的/etc/hosts添加了 当前主机的 ‘ NAT分配的IP controller’,RabbitMQ添加用户报错。
    一对简单的IPV6 SOCKET代码
    字节转换函数
    libevent笔记6:ssl bufferevent
    libevent笔记5:水位watermarks
    libevent笔记4:Filter_bufferevent过滤器
    libevent笔记3:evbuffer
  • 原文地址:https://www.cnblogs.com/mumulailai/p/14912433.html
Copyright © 2011-2022 走看看