I have a web application that has an admin login page.
When i try to login to the admin page i get this error message:
Type Exception Report
Message Unable to compile class for JSP:
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [13] in the jsp file: [/adminlogact.jsp]
databasecon cannot be resolved
10:
11: // String user=null;
12: //String password=null;
13: Connection con=databasecon.getconnection();
14: Statement st = con.createStatement();
15: ResultSet rs = st.executeQuery("select * from admin where user='"+username+"' and pwd='"+password+"'");
16: if(rs.next())
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:214)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:531)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:398)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:368)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327)
javax.servlet.http.HttpServlet.service(HttpServlet.java:623)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
Note The full stack trace of the root cause is available in the server logs.
here is the admin page code:
<%@page import="java.sql.*"%>
<%@page import="databaseconnection.*"%>
<%@ page session="true" %>
<%
String username = request.getParameter("username");
System.out.println(username);
String password = request.getParameter("password");
System.out.println(password);
try{
// String user=null;
//String password=null;
Connection con=databasecon.getconnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from admin where user='"+username+"' and pwd='"+password+"'");
if(rs.next())
{
String user = rs.getString(2);
session.setAttribute("user",user);
System.out.println("User:"+user);
response.sendRedirect("adminhome.jsp");
}
else
{
response.sendRedirect("admin.html?m1=LoginFail");
}
}
catch(Exception e)
{
System.out.println("Error in adminlogact"+e.getMessage());
}
%>
here is the databasecon java code:
package databaseconnection;
import java.sql.*;
public class databasecon
{
static Connection co;
public static Connection getconnection()
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
co = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","mypass");
}
catch(Exception e)
{
System.out.println("Database Error"+e);
}
return co;
}
}
I am able to login tot he database and view the tables just fine but seems tomcat cannot find the database.
The catalina log dosent have any errors