这是我的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");
}
}
}
答案 0 :(得分:0)
更改
BufferedReader b = new BufferedReader(new FileReader("E://ConferenceRoomBooking//UsersDetails.txt"));
到
BufferedReader b = new BufferedReader(new FileReader("E:\\ConferenceRoomBooking\\UsersDetails.txt"));