handlelogin.java

来自「纯粹jsp的留言板,使用了mvc」· Java 代码 · 共 73 行

JAVA
73
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package messagepad.servlets;import messagepad.beans.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;/** * * @author Administrator */public class handleLogin extends HttpServlet{    public void init(ServletConfig config) throws ServletException{        super.init(config);        try{            Class.forName("com.mysql.jdbc.Driver");                    }        catch(Exception e){        }    }    public void doPost(HttpServletRequest request ,HttpServletResponse response)            throws ServletException,IOException{            //String rName=request.getParameter("rootid");            //String rPass=request.getParameter("rootpassword");                        Connection con;            Statement sql;            ResultSet rs;            try{                String url="jdbc:mysql://localhost/taotao";                String user="taotao";                String password=".nothing";                con=DriverManager.getConnection(url,user,password);                String rName=request.getParameter("rootid");                //byte b[]=str.getBytes("UTF-8");                //str=new String(b);                String rPass=request.getParameter("rootpassword");                HttpSession session = request.getSession();                                //byte b[]=strContent.getBytes("UTF-8");                //strContent=new String(b);                String checkCondition="select id,password from managers";                sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);                                rs=sql.executeQuery(checkCondition);                rs.next();                //RequestDispatcher dispatcher=request.getRequestDispatcher("index.jsp");                //dispatcher.forward(request, response);                                //String r=new String("root");                //PrintWriter out=response.getWriter();                //out.print("<html><body>xxx</body><html>");                if(rs.getString("password").equals(rPass)&&rs.getString("id").equals(rName)){                    response.sendRedirect("rootindex.jsp");                }                else{                    response.sendRedirect("login.jsp");                }            }            catch(SQLException e){            }                }    public void doGet(HttpServletRequest request ,HttpServletResponse response)            throws ServletException,IOException{                doPost(request,response);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?