type Exception report

message Unable to compile class for JSP:

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: 22 in the jsp file: /index_submit.jsp
name cannot be resolved to a variable
19: String url = "jdbc:mysql://localhost:3306/mit";
20: String user = "root";
21: String dbpsw = "root";
22: String sql = "select * from logindetails where rollno='"+name+"'";
23: String name = request.getParameter("rollno");
24: String password = request.getParameter("password");



Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:446)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:335)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


                                        my code is

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.DriverManager.*" %>
<%@ page import="java.sql.Statement.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<%! String userdbName;
String userdbPsw;
%>
<%
Connection con= null;
PreparedStatement ps = null;
ResultSet rs = null;
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/mit";
String user = "root";
String dbpsw = "root";
String sql = "select * from logindetails where rollno='"+name+"'";
String name = request.getParameter("rollno");
String password = request.getParameter("password");
try{
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(url, user, dbpsw);
ps = con.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, password);
rs = ps.executeQuery();
if(rs.next())
{ 
userdbName = rs.getString("name");
userdbPsw = rs.getString("password");
if(name.equals(userdbName) && password.equals(userdbPsw))
{
session.setAttribute("name",userdbName);
response.sendRedirect("home.jsp"); 
} 
}
else
response.sendRedirect("error.jsp");
rs.close();
ps.close(); 
}
catch(SQLException sqe)
{
out.println(sqe);
} 
%>
%>
</body>
</html>

You are initializing the string name on line 23 but you tried to use it in line 22.

to be more specific:

String sql = "select * from logindetails where rollno='"+name+"'";
String name = request.getParameter("rollno");

change the order in which you use these two lines.

even better: start studying servlets. it's very bad practice to have Java code in your .jsp file. the Java code is supposed to implement the business logic, the .jsp file is purely UI, this should not be mixed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.