如何从textfile检查用户和密码以进行登录

时间:2017-10-23 18:12:28

标签: java jsp

这是我的loginServlet,也没有为文件提供路径:

String uname = request.getParameter("uname");
String pass = request.getParameter("pass");

BufferedReader b = new BufferedReader(new FileReader("E://ConferenceRoomBooking//UsersDetails.txt"));
String ln = "";
String kn = "";
String gn = "";
int lnnum = 0;

while ((ln = b.readLine()) != null) {

    String[] values = ln.split(",");
    // System.out.println(values[0]);
    // System.out.println(values[1]);
    for (String str : values) {
        String[] element = str.split("!");
        lnnum++;

        if (uname.equals(gn) && pass.equals(kn)) {
            HttpSession session = request.getSession();
            session.setAttribute("username", uname);
            response.sendRedirect("BookingRoom.jsp");

        } else {

            response.sendRedirect("error.jsp");

        }
    }
}

1 个答案:

答案 0 :(得分:0)

更改

BufferedReader b = new BufferedReader(new FileReader("E://ConferenceRoomBooking//UsersDetails.txt"));

BufferedReader b = new BufferedReader(new FileReader("E:\\ConferenceRoomBooking\\UsersDetails.txt"));