-1

is there any one to please help me out of this error below

type Exception report message

description The server encountered an internal error () that prevented it from fulfilling this request. 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

Below are listed errors along with login.jsp file

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

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>");
    }
%>

this is the error displayed

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 logs

<!-- begin snippet: js hide: false -->
Taryn
  • 242,637
  • 56
  • 362
  • 405
Angular zeus
  • 23
  • 1
  • 9
  • I bet you've found the `username` vs `userName` typo by now. Might as well delete this question as it's just a typographical error and has problems with the JavaScript snippet tags as well. – Arjan Aug 23 '16 at 06:11

1 Answers1

0

You should probably avoid writing java code in JSP. It is not a good practise. See this link. Try putting your code in a Try Catch Block and the error should be resolved.

Community
  • 1
  • 1
sTg
  • 4,313
  • 16
  • 68
  • 115