2014-10-28 120 views
-1

沒有任何一個請幫我出這個錯誤的下面JSP登錄頁面錯誤

類型異常報告 消息

說明服務器遇到內部錯誤(),阻止其完成此請求。 例外

org.apache.jasper.JasperException:10在jsp文件:無法編譯類JSP:在行發生

錯誤/login.jsp 用戶名不能被解析爲一個變量

與login.jsp的文件一起下面列出的錯誤

的login.jsp

<%@ page import="java.sql.*"%> 
<% 
    String userName = request.getParameter("username");  
    String password = request.getParameter("password"); 
    Class.forName("com.mysql.jdbc.Driver"); 
    Connection con = DriverManager.getConnection("jdbc:mysql://50.62.23.184:3306/gtuser_sched1", 
      "gtuser_grp1", "capmap"); 
    Statement st = con.createStatement(); 
    ResultSet rs; 
    rs = st.executeQuery("select * from users where userName='" +username + "' and password='" +password + "'"); 
    if (rs.next()) { 
     session.setAttribute("userid", userName); 
     response.sendRedirect("success.jsp"); 
    } else { 
     out.println("Invalid password <a href='index.jsp'>try again</a>"); 
    } 
%> 

異常

exception 
org.apache.jasper.JasperException: Unable to compile class for JSP: 
An error occurred at line: 10 in the jsp file: /login.jsp 
username cannot be resolved to a variable 
7:    "gtuser_grp1", "Capstone1"); 
8:  Statement st = con.createStatement(); 
9:  ResultSet rs; 
10:  rs = st.executeQuery("select * from users where userName='" +username + "' and password='" +password + "'"); 
11:  if (rs.next()) { 
12:   session.setAttribute("userid", userName); 
13:   response.sendRedirect("success.jsp"); 
Stacktrace: 
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) 
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) 
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:446) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:327) 
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:607) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 
note The full stack trace of the root cause is available in the JBoss Web/7.0.10.Final 

login.jsp//file where im providing login credentials 
 

 
<%@ page import="java.sql.*"%> 
 
<% 
 
    String userName = request.getParameter("username");  
 
    String password = request.getParameter("password"); 
 
    Class.forName("com.mysql.jdbc.Driver"); 
 
    Connection con = DriverManager.getConnection("jdbc:mysql://50.62.23.184:3306/gtuser_sched1", 
 
      "gtuser_grp1", "capmap"); 
 
    Statement st = con.createStatement(); 
 
    ResultSet rs; 
 
    rs = st.executeQuery("select * from users where userName='" +username + "' and password='" +password + "'"); 
 
    if (rs.next()) { 
 
     session.setAttribute("userid", userName); 
 
     response.sendRedirect("success.jsp"); 
 
    } else { 
 
     out.println("Invalid password <a href='index.jsp'>try again</a>"); 
 
    } 
 
%>

這是錯誤顯示

exception 
 
org.apache.jasper.JasperException: Unable to compile class for JSP: 
 
An error occurred at line: 10 in the jsp file: /login.jsp 
 
username cannot be resolved to a variable 
 
7:    "gtuser_grp1", "Capstone1"); 
 
8:  Statement st = con.createStatement(); 
 
9:  ResultSet rs; 
 
10:  rs = st.executeQuery("select * from users where userName='" +username + "' and password='" +password + "'"); 
 
11:  if (rs.next()) { 
 
12:   session.setAttribute("userid", userName); 
 
13:   response.sendRedirect("success.jsp"); 
 
Stacktrace: 
 
\t org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) 
 
\t org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) 
 
\t org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:446) 
 
\t org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) 
 
\t org.apache.jasper.compiler.Compiler.compile(Compiler.java:340) 
 
\t org.apache.jasper.compiler.Compiler.compile(Compiler.java:327) 
 
\t org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:607) 
 
\t org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312) 
 
\t org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) 
 
\t org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) 
 
\t javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 
 
note The full stack trace of the root cause is available in the JBoss Web/7.0.10.Final logs 
 

 
<!-- begin snippet: js hide: false -->

+0

我敢打賭,你現在已經找到了'用戶名'和'用戶名'的錯字。不妨刪除這個問題,因爲這只是一個印刷錯誤,並且也存在JavaScript片段標籤的問題。 – Arjan 2016-08-23 06:11:09

回答

0

您應該避免在JSP中編寫Java代碼。這不是一個好習慣。看到這個link。嘗試將代碼放在Try Catch塊中,並且應該解決錯誤。