hi,
im making login page using jsp.user names and password entered are matched wit the db.
have placed db connection code in a java classlogin.java...The directory path is
webapps->myfolder->all jsp and html files
webapps->myfolder->WEB-INF->classes->test->login.java

I entered the url in browser also perfectly fine..http://localhost:8085/myfolder/mainpage.jsp

i set the PATH and CLASSPATH variables in control panel too as..

control panel->system->advanced->environment variables->edit->PATH-> ;c:\j2sdk1.4_01\bin (this is the version of java im using)

control panel->system->advanced->environment variables->new->CLASSPATH-> . ; C:\myfolder\WEB-INF\classes

but server still shows followin error..
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: 4 in the jsp file: /process.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\myfolder\process_jsp.java:43: package foo does not exist
foo.Login idHandler = null;
^

An error occurred at line: 4 in the jsp file: /process.jsp

Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\myfolder\process_jsp.java:45: package foo does not exist
idHandler = (foo.Login) pageContext.getAttribute("idHandler", PageContext.REQUEST_SCOPE);
^

An error occurred at line: 4 in the jsp file: /process.jsp

Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\myfolder\process_jsp.java:48: package foo does not exist
idHandler = (foo.Login) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "foo.Login");
^
3 errors

can you please tell whts missin or wrong?..

Recommended Answers

All 8 Replies

Are you sure you provided the path to JDK instead of JRE during Tomcat installation? If yes, then paste your code (JSP along with Java files) and we will see what can be done.

hi,
the IT helpdesk guy installed it for me in office.how can i check if the path provided was to jdk or jre?..


anyway this is the jsp and java code im using..

1) HTML FILE

<html>
<title>
administration login
</title>
<center><img src= "Pictures\top.gif">

<head><h1><font color="white" face="monotype corsiva">
LOGIN</center></h1>
</font>
</head>

<hr>

<body bgcolor="009999" >

<form action="process.jsp" method="post">

<center>

USER ID &nbsp; &nbsp; &nbsp; <input type="text" name="AQC1_UID" value=""><br><br><br><br>
PASSWORD &nbsp; &nbsp; &nbsp; <input type="password" name="AQC1_USER_PWD" value=""><br><br><br><br><br>
</font>

<input type="submit" name="login" value="login">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="reset" name="cancel" value="cancel">

</center>

</form>

</body>

</html>

2) JSP FILE


<%@ page import="java.util.*" %>

%@ page import="foo.Login" %>

<jsp:useBean id="idHandler" class="foo.Login" scope="request">

<jsp:setProperty name="idHandler" property="*"/>

</jsp:useBean>

<%
String arg1=request.getParameter("AQC1_UID");
String arg2=request.getParameter("AQC1_USER_PWD");

if (idHandler.authenticate(arg1,arg2)==true) { // checking
//out.println(arg1);
%>
<jsp:forward page="second.jsp"/>
<%
} else {
%>
<jsp:forward page="third.jsp"/>
<%
}
%>


3) JAVA BEAN that contains DATABASE CONNECTION

package foo;
import java.sql.*;

public class Login {

private String AQC1_UID = "";
private String AQC1_USER_PWD = "";

public Login() {
}

public void setUsername(String AQC1_UID) {
this.AQC1_UID=AQC1_UID;
}

public void setPassword(String AQC1_USER_PWD) {
this.AQC1_USER_PWD=AQC1_USER_PWD;
}


public boolean validate(String user,
String password) {
String query="select * from AIP_QM_CONTROL1";
String DbUserName="";
String DbPassword="";
String finalUser="";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:AIP_QM_Control1");
Statement stat=con.createStatement();
ResultSet rst=stat.executeQuery(query);
while(rst.next())

{
DbUserName=rst.getString("AQC1_UID");

DbPassword=rst.getString("AQC1_USER_PWD");

if (username.equals(DbUserName) &&
password.equals(DbPassword)) {

break;
}


}
return true;
}catch(Exception e){

e.printStackTrace();
return false;
}
}}

please help..im stuck because of this..

> how can i check if the path provided was to jdk or jre?

Create a very simple/minimalistic JSP which just outputs "Hello World" or some other random text, and try to access your web application. If it doesn't compile, it means that the path supplied was of JRE and not JDK.

> control panel->system->advanced->environment variables->new->CLASSPATH-> . ;

You don't explicitly need to set the CLASSPATH that way, remove it. The Tomcat class loader automatically takes care of it and makes sure it loads all the classes present in the WEB-INF/classes folder. The directory structure needs to look something like:

webapps
|--- myapplication
      |--- jsp file
      |--- WEB-INF
             |--- web.xml  
             |--- classes
                   |--- foo
                         |--- Login.class

Also, don't use scriptlets in your code, use JSTL. And first and foremost, read a bit more about the basics of Servlets/JSP's from the link suggested by me in one of the other threads. There is no point in trying to program something without even knowing the basics of it.

Hey..i tried everythin you told.Even a simple java application that prints a statement is giving 'exception in thread "main" java.lang.NoClassDefFound exception'.but it comiples just fine.So this means problem might not be wit tomcat...

hi,
the IT helpdesk guy installed it for me in office.how can i check if the path provided was to jdk or jre?..

Checking path in windows in Command Prompt (Start/All Programs/Accessories/Command Prompt or Start/Run/ type cmd or even faster keybord with windods key+r) type PATH and return should contain direction to your java instalation in similar format

PATH=C:\Program Files\Java\jdk1.6.0_03\bin;

In unix base systems echo $PATH. Also I found to be more reliable to have path for jdk instead of jre.

Peter, the OP wanted to know how to check whether a JDK or a JRE path was provided during installation and not the environment variable PATH.

Ankita B, try running a simple servlet / jsp without using any beans and let us know if it works. The exception message clearly states it has got something to do with the classpath and it wasn't able to find the class you requested. Also you need to provide us the directory structure you are using, the problem is definitely at your end.

Hi,
this is the html file----

<html>
<body>
<h2>Mathematical function</h2>
<font size=4 face="verdana" color="#112244>
<form method="post" action="calculate.jsp">
<input type="radio" name="r1" value="add" checked="false">addition<br><br>


<input type="radio" name="r1" value="subtract" checked="false">subtraction<br><br>


Enter two numbers:
<input type="text" name="t1" value="">
<input type="text" name="t2" value="">
<br><br>


<input type="submit" name="b1">
</form>
</body>
</head>
</html>

I am getting the following error runnin a simple jsp file-----

<%--import the java packages--%>


<%@ page language="java" %>
<%@ page import="java.lang.*"%>


<html>
<font size=4 face="verdana" color=#112244>
<body>


<% String str=request.getParameter("r1");
String str1=request.getParameter("t1");
String str2=request.getParameter("t2");


String final_output="";


int num1=0;
int num2=0;
int num3=0;


num1=Integer.parseInt(str1);
num2=Integer.parseInt(str2);


if(str.equals("add"))
{
num3=num1+num2;
final_output="addition";
}
if(str.equals("subtract"))
{
num3=num1-num2;
final_output="subtraction";
}


%>
selected mathematical function is:<%= final_output %>



<%
Integer in=new Integer(num3);
System.out.println("result is"+in.toString());
%>


</body>
</html>

Error is------

HTTP Status 500 -


--------------------------------------------------------------------------------


type Exception report


message


description The server encountered an internal error () that prevented it from fulfilling this request.


exception


org.apache.jasper.JasperException: null
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
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:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:536)



root cause


java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:394)
at java.lang.Integer.parseInt(Integer.java:476)
at org.apache.jsp.calculate_jsp._jspService(calculate_jsp.java:58)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
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:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:536)

The directory structure is as follows:-

C->j2sdk1.4.1_01


C->Program Files->Apache Group->Tomcat 4.1->webapps->myfolder->jsp & html files


C->Program Files->Apache Group->Tomcat 4.1->webapps->myfolder->WEB-INF->classes->loginpackage->Login.java

So what is going wrong?

> <%@ page language="java" %>
> <%@ page import="java.lang.*"%>
These two lines are not necessary. You don't need to specify the language. The package java.lang.* is implicitly imported, you don't need explicit import statements. This is the very basic of Java programming which every java programmer must be aware of.

> <font size=4 face="verdana" color="#112244>
Font tag is now deprecated. Use CSS instead.

> So what is going wrong?
The error is very clear. When debugging such types of problems, always look at the root cause which has triggered the entire exception chain. The root cause in your case is java.lang.NumberFormatException: null . This means your parseInt() method is getting a null which implies that either str1 or str2 is null .

You will now need to debug your code by either putting a lot of print statements or debugging using an IDE like Eclipse.

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.