t1441332354 2018-05-21 08:24 采纳率: 71.8%
浏览 654
已采纳

关于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条回答 默认 最新

  • 潘zoe 2018-05-21 08:38
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 java代码写在记事本上后在cmd上运行时无报错但又没生成文件
  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败
  • ¥15 复合卡卡号轨道写入芯片卡