org.apache.jasper.JasperException: An exception occurred processing JSP page /ShopLoginCheck2.jsp at line 60
57: <br> You have entered the wrong credentials!
58: <br> Press any key to go back to the Login page
59: <%
60: String takeIn = sc.next();
61: session.invalidate();
62: response.sendRedirect("WelcomeShop.jsp");
63: }
在上面的代码中,由于显示的错误,我无法继续。
有什么建议可以摆脱它吗?
按要求添加更多代码:
Scanner sc = new Scanner(System.in);
String s_id_string=(String)request.getParameter("s_id");
int s_id=0;
if(s_id_string !=null)
{
s_id = Integer.parseInt(s_id_string);
}
String s_name=(String)request.getParameter("s_name");
String s_password=(String)request.getParameter("s_password");
Statement stmt1 = con.createStatement();
ResultSet rs1 = stmt1.executeQuery("SELECT * FROM ShopSystem.Shop where s_id='"+s_id+"' AND s_name='"+s_name+"' AND s_password='"+s_password+"'");
if(rs1.next())
{
if((s_id == rs1.getInt("s_id")) && (s_name.equals(rs1.getString("s_name"))) && (s_password.equals(rs1.getString("s_password"))))
{
session = request.getSession();
session.setAttribute("s_id", s_id);
session.setAttribute("s_name", s_name);
session.setAttribute("s_password", s_password);
response.sendRedirect("ShopMenu3.jsp");
}
}
else
{
%>
<br> You have entered the wrong credentials!
<br> Press any key to go back to the Login page
<%
String takeIn = sc.next();
session.invalidate();
response.sendRedirect("WelcomeShop.jsp");
}
sc.close();
并且我不打算以任何方式使用takeIn。 sc是一个Scanner对象
答案 0 :(得分:0)
删除行String takeIn = sc.next();
,因为您不打算使用此方法调用的返回值。导致该错误是因为Scanner
对象sc
中没有可用数据。见http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#next()。
此外,在致电Scanner.next()
之前,您应始终使用Scanner.hasNext()
方法检查是否有任何可用数据。在你的情况下是sc.hasNext()
。