I have created a java class file in a folder in WEB-INF/classes/myproject
I am getting this error when I call it from a jsp file
root cause
java.lang.InstantiationException: class myproject.Validate : java.lang.InstantiationException: myproject.Validate
at org.apache.jsp.index$jsp._jspService(index$jsp.java:113)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
This line is causing the error(in the jsp file)
<jsp:useBean id="myOb" class="myproject.Validate" />
This is the code for the class file
ackage myproject;
import java.util.HashSet;
import java.util.Set;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.*;
import java.sql.*;
import java.io.Serializable;
public class Validate implements java.io.Serializable
{
public static final String SQL_SELECT = "select m_users.id, m_users.name, m_users.level_no from m_users. where m_users.id=? and m_users.password=?";
private Connection cnn;
public int user_ID;
public int levelId;
public String chkUsr,chkPass;
public Validate( Connection cnn )
{
if ( cnn == null ) throw new IllegalArgumentException( "Connection object is null" );
this.cnn = cnn;
}
public void checkUser(String usr, String passwd)
{
PreparedStatement stmt;
ResultSet rs;
chkUsr = usr;
chkPass = passwd;
if(chkUsr.length() >0 && chkUsr != null && chkPass.length() > 0 && chkPass != null)
{
try
{
stmt = cnn.prepareStatement(SQL_SELECT ,ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
stmt.setString(1,chkUsr);
stmt.setString(2,chkPass);
rs = stmt.executeQuery();
if(rs != null)
{
while(rs.next())
{
user_ID = rs.getInt("usr_id"
}
rs.close();
}
if(stmt != null)
{
stmt.close();
}
}
catch(SQLException sql)
{
System.out.println( sql);
}
}
}
public int ifValidUser()
{
System.out.println(user_ID);
return user_ID;
}
}
I am new in using beans , I got the same error in another place, I could do with some help in instantiating class files in tomcat.
I am using redhat linux 9.0, Postgresql 7.3 and Tomcat 4.16
I am getting this error when I call it from a jsp file
root cause
java.lang.InstantiationException: class myproject.Validate : java.lang.InstantiationException: myproject.Validate
at org.apache.jsp.index$jsp._jspService(index$jsp.java:113)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
This line is causing the error(in the jsp file)
<jsp:useBean id="myOb" class="myproject.Validate" />
This is the code for the class file
ackage myproject;
import java.util.HashSet;
import java.util.Set;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.*;
import java.sql.*;
import java.io.Serializable;
public class Validate implements java.io.Serializable
{
public static final String SQL_SELECT = "select m_users.id, m_users.name, m_users.level_no from m_users. where m_users.id=? and m_users.password=?";
private Connection cnn;
public int user_ID;
public int levelId;
public String chkUsr,chkPass;
public Validate( Connection cnn )
{
if ( cnn == null ) throw new IllegalArgumentException( "Connection object is null" );
this.cnn = cnn;
}
public void checkUser(String usr, String passwd)
{
PreparedStatement stmt;
ResultSet rs;
chkUsr = usr;
chkPass = passwd;
if(chkUsr.length() >0 && chkUsr != null && chkPass.length() > 0 && chkPass != null)
{
try
{
stmt = cnn.prepareStatement(SQL_SELECT ,ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
stmt.setString(1,chkUsr);
stmt.setString(2,chkPass);
rs = stmt.executeQuery();
if(rs != null)
{
while(rs.next())
{
user_ID = rs.getInt("usr_id"
}
rs.close();
}
if(stmt != null)
{
stmt.close();
}
}
catch(SQLException sql)
{
System.out.println( sql);
}
}
}
public int ifValidUser()
{
System.out.println(user_ID);
return user_ID;
}
}
I am new in using beans , I got the same error in another place, I could do with some help in instantiating class files in tomcat.
I am using redhat linux 9.0, Postgresql 7.3 and Tomcat 4.16