关于jsp页面信息拦截处理的问题

这是一个简单的登录页面,登录信息传到LogincheckServlet里

 <title>登录界面</title>
</head>
<body>
    <center>
        <h1 style="color:red">用户登录</h1>
            <form id="indexform" name="indexform" action="LogincheckServlet" method="post">
                <table border="0">
                    <tr>
                        <td>账号:</td>
                        <td><input type="text" name="username"></td>
                    </tr>
                    <tr>
                        <td>密码:</td>
                        <td><input type="password" name="pass"></td>
                    </tr>
                </table>
                <br>
                    <input type="submit" value="登录" style="color:#BC8F8F">
            </form>
    </center>
</body>
</html>

这是接收信息的后台

 package com.sy;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

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 org.fkjava.util.MD5;

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

    /**
     * @see HttpServlet#HttpServlet()
     */
    public LogincheckServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @SuppressWarnings("unused")
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        MD5 pwd = new MD5();
        String username = new String(request.getParameter("username").getBytes("ISO8859_1"),"UTF-8");
        String password = pwd.getMD5(request.getParameter("password"));

        try{
            Class.forName("com.mysql.jdbc.Driver");

            String url = "jdbc:mysql://XXXXXXXXXX";

            String usename = "XXXXXXXX";

            String psw = "XXXXXXX";

            Connection conn = DriverManager.getConnection(url,usename,psw);

            Statement stmt = conn.createStatement();
            if(conn != null){
                String sql = "select IsAdmin from LoginUser where UserName = '"+username+"' and LoginPwd = '"+password+"'";
                ResultSet rs = stmt.executeQuery(sql);
                List<Administrator> list = new ArrayList<Administrator>();
                if(rs.next()){
                    Administrator ait = new Administrator();
                    ait.setIsAdmin(rs.getInt("IsAdmin"));
                    list.add(ait);
                    request.setAttribute("list",list);
                }else{
                    System.out.println("密码错误或用户名不存在,请重新输入!");
                }
                rs.close();
                stmt.close();
                conn.close();
            }else{
                System.out.print("数据库链接失败!");
            }
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }catch(SQLException e){
            e.printStackTrace();
        }

        List<Administrator> list = (List<Administrator>)request.getAttribute("list");
        if(list == null || list.size() < 1){
            System.out.print("没有数据");
        }else{
            for(Administrator ait : list){
                if(ait.getIsAdmin() == 1){
                    response.sendRedirect("AIS.jsp");
                }else if(ait.getIsAdmin() == 0){
                    response.sendRedirect("Administrator.jsp");
                }
            }
        }

    }

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

}

现在我运行jsp页面,发现不管填什么信息都会跳转到后台,但是什么都不运行。感觉就像前端的信息被拦截到后台但后台没有代码运行,呈现一片空白。这是为什么呢?有什么办法能让后台的程序运行起来

4个回答

你是用的POST提交的话在对应的servlet中就要用对应的doPOST()方法

form表单的提交方法是POST方法,servlet中的doPost方法没有没有处理逻辑

你的doPost方法中写调用doGet方法:doGet(request,response);

你的method写的是post,但是你的代码是在doGet写的。把method="post"改成method="get"
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!