danBosh
asked on
jsp and javabean problem
I have basic html page that looks like this:
<%@ page import="database.*" %>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body>
test
</body>
</html>
this page is in my server ROOT and the Conc class is in ROOT\database, but i get this error:
org.apache.jasper.JasperEx ception: Unable to compile class for JSP
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\_\inde x_jsp.java :7: package database does not exist
import database.*;
^
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\_\inde x_jsp.java :43: package database does not exist
database.Conc db = null;
^
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\_\inde x_jsp.java :45: package database does not exist
db = (database.Conc) pageContext.getAttribute(" db", PageContext.SESSION_SCOPE) ;
^
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\_\inde x_jsp.java :48: package database does not exist
db = (database.Conc) java.beans.Beans.instantia te(this.ge tClass().g etClassLoa der(), "database.Conc");
^
4 errors
at org.apache.jasper.compiler .DefaultEr rorHandler .javacErro r(DefaultE rrorHandle r.java:130 )
at org.apache.jasper.compiler .ErrorDisp atcher.jav acError(Er rorDispatc her.java:2 93)
at org.apache.jasper.compiler .Compiler. generateCl ass
any idea what i have done wrong
<%@ page import="database.*" %>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body>
test
</body>
</html>
this page is in my server ROOT and the Conc class is in ROOT\database, but i get this error:
org.apache.jasper.JasperEx
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
import database.*;
^
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
database.Conc db = null;
^
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
db = (database.Conc) pageContext.getAttribute("
^
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
db = (database.Conc) java.beans.Beans.instantia
^
4 errors
at org.apache.jasper.compiler
at org.apache.jasper.compiler
at org.apache.jasper.compiler
any idea what i have done wrong
Hi,
If you deploy your package database.* as a set of separate class files then put them into ROOT\WEB-INF\classes directory.
If you deploy your package database.* as a .jar file then you shouldput it to ROOT\WEB-INF\lib directory.
If you deploy your package database.* as a set of separate class files then put them into ROOT\WEB-INF\classes directory.
If you deploy your package database.* as a .jar file then you shouldput it to ROOT\WEB-INF\lib directory.
ASKER
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.JasperEx ception: /index.jsp(1,19) equal symbol expected
at org.apache.jasper.compiler .DefaultEr rorHandler .jspError( DefaultErr orHandler. java:94)
at org.apache.jasper.compiler .ErrorDisp atcher.dis patch(Erro rDispatche r.java:428 )
at org.apache.jasper.compiler .ErrorDisp atcher.jsp Error(Erro rDispatche r.java:126 )
at org.apache.jasper.compiler .Parser.pa rseAttribu te(Parser. java:169)
i did that i i now get this, what does it mean?
--------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperEx
at org.apache.jasper.compiler
at org.apache.jasper.compiler
at org.apache.jasper.compiler
at org.apache.jasper.compiler
i did that i i now get this, what does it mean?
can you double check your jsp syntax? are you missing one "="? can you recopy and paster you code here again? thanks.
ASKER
<%@ page import="database.*%>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">
<p align="center"><b><font face="Arial">User Name: </font></b>&nbs p;
<input type ="text" name="loginName" size="19"></p>
<p align="center"><b><font face="Arial">Password:&nbs p; </ font></b>& nbsp;  ;
<input type ="text" name="password" size="19"> </p>
<p align="center">
<input type="submit" value="Login"> </p>
</form>
<%
if( (request.getParameter("log inName") != null) && (request.getParameter("pas sword") != null) )
{
if (true == db.Conc(request.getParamet er("loginN ame"),requ est.getPar ameter("pa ssword") ))
{
%>
<p align="center">good
<%
}
else
{
%>
bad
<%
}
}
%> </p>
</body>
</html>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">
<p align="center"><b><font face="Arial">User Name: </font></b>&nbs
<input type ="text" name="loginName" size="19"></p>
<p align="center"><b><font face="Arial">Password:&nbs
<input type ="text" name="password" size="19"> </p>
<p align="center">
<input type="submit" value="Login"> </p>
</form>
<%
if( (request.getParameter("log
{
if (true == db.Conc(request.getParamet
{
%>
<p align="center">good
<%
}
else
{
%>
bad
<%
}
}
%> </p>
</body>
</html>
ASKER
<%@ page import="database.*%>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">
<p align="center"><b><font face="Arial">User Name: </font></b>&nbs p;
<input type ="text" name="loginName" size="19"></p>
<p align="center"><b><font face="Arial">Password:&nbs p; </ font></b>& nbsp;  ;
<input type ="text" name="password" size="19"> </p>
<p align="center">
<input type="submit" value="Login"> </p>
</form>
<%
if( (request.getParameter("log inName") != null) && (request.getParameter("pas sword") != null) )
{
if (true == db.Conc(request.getParamet er("loginN ame"),requ est.getPar ameter("pa ssword") ))
{
%>
<p align="center">good
<%
}
else
{
%>
bad
<%
}
}
%> </p>
</body>
</html>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">
<p align="center"><b><font face="Arial">User Name: </font></b>&nbs
<input type ="text" name="loginName" size="19"></p>
<p align="center"><b><font face="Arial">Password:&nbs
<input type ="text" name="password" size="19"> </p>
<p align="center">
<input type="submit" value="Login"> </p>
</form>
<%
if( (request.getParameter("log
{
if (true == db.Conc(request.getParamet
{
%>
<p align="center">good
<%
}
else
{
%>
bad
<%
}
}
%> </p>
</body>
</html>
ASKER
<%@ page import="database.*%>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">
<p align="center"><b><font face="Arial">User Name: </font></b>&nbs p;
<input type ="text" name="loginName" size="19"></p>
<p align="center"><b><font face="Arial">Password:&nbs p; </ font></b>& nbsp;  ;
<input type ="text" name="password" size="19"> </p>
<p align="center">
<input type="submit" value="Login"> </p>
</form>
<%
if( (request.getParameter("log inName") != null) && (request.getParameter("pas sword") != null) )
{
if (true == db.Conc(request.getParamet er("loginN ame"),requ est.getPar ameter("pa ssword") ))
{
%>
<p align="center">good
<%
}
else
{
%>
bad
<%
}
}
%> </p>
</body>
</html>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">
<p align="center"><b><font face="Arial">User Name: </font></b>&nbs
<input type ="text" name="loginName" size="19"></p>
<p align="center"><b><font face="Arial">Password:&nbs
<input type ="text" name="password" size="19"> </p>
<p align="center">
<input type="submit" value="Login"> </p>
</form>
<%
if( (request.getParameter("log
{
if (true == db.Conc(request.getParamet
{
%>
<p align="center">good
<%
}
else
{
%>
bad
<%
}
}
%> </p>
</body>
</html>
ASKER
sorry about that, dont know how it happened
Your first line should be:
<%@ page import="database.*" %>
<%@ page import="database.*" %>
Your first line should be:
<%@ page import="database.*" %>
<%@ page import="database.*" %>
ASKER
yeah i just found that but when i corrected it, i got the orginal error:
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.JasperEx ception: Unable to compile class for JSP
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\_\inde x_jsp.java :7: package database does not exist
import database.*;
^
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\_\inde x_jsp.java :43: package database does not exist
database.Conc db = null;
^
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\_\inde x_jsp.java :45: package database does not exist
db = (database.Conc) pageContext.getAttribute(" db", PageContext.SESSION_SCOPE) ;
^
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\_\inde x_jsp.java :48: package database does not exist
db = (database.Conc) java.beans.Beans.instantia te(this.ge tClass().g etClassLoa der(), "database.Conc");
^
4 errors
at org.apache.jasper.compiler .DefaultEr rorHandler .javacErro r(DefaultE rrorHandle r.java:130 )
at org.apache.jasper.compiler .ErrorDisp atcher.jav acError(Er rorDispatc her.java:2 93)
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.JasperEx
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
import database.*;
^
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
database.Conc db = null;
^
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
db = (database.Conc) pageContext.getAttribute("
^
An error occurred at line: 1 in the jsp file: /index.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
db = (database.Conc) java.beans.Beans.instantia
^
4 errors
at org.apache.jasper.compiler
at org.apache.jasper.compiler
Please, tell what files/directories do you have under your application ROOT directory.
where is your Conc.class file, also make sure this is the first line of you Conc.java file.
package database;
if not, add it and recompile and restart server.
package database;
if not, add it and recompile and restart server.
ASKER
first line in Conc.java is package database;
index.jsp is in the tomcat 4.1\webapps\ROOT
and Conc.class is in tomcat 4.1\webapps\ROOT\WEB-INF\c lasses\dat abase
index.jsp is in the tomcat 4.1\webapps\ROOT
and Conc.class is in tomcat 4.1\webapps\ROOT\WEB-INF\c
did you restart your server? and do a refresh on your browser.
there is no reason it still doesn't work after done all of these. it is a very basic bean problem that has been fixed million time by following the steps posted. just repeated it again:
1. make "package database" as the first line of Conc.java
2. compile Conc.java into Conc.class
3. put Conc.class in WEB-INF\classes\database, and make sure everybody have permission to read this file and dir path.
4. include "<jsp:useBean id="db" scope="session" class="database.Conc"/>" in a very simple jsp page.
5. double check all the dirnames and filenames
6. restart the server.
7. access the simple jsp page.
8. you shouldn't see "package database does not exist" error now.
there is no reason it still doesn't work after done all of these. it is a very basic bean problem that has been fixed million time by following the steps posted. just repeated it again:
1. make "package database" as the first line of Conc.java
2. compile Conc.java into Conc.class
3. put Conc.class in WEB-INF\classes\database, and make sure everybody have permission to read this file and dir path.
4. include "<jsp:useBean id="db" scope="session" class="database.Conc"/>" in a very simple jsp page.
5. double check all the dirnames and filenames
6. restart the server.
7. access the simple jsp page.
8. you shouldn't see "package database does not exist" error now.
ASKER
i just went through your list and it still didn't work. Thanks for trying, why do i have to put the .class file in the WEB-INF\classes directory is this some sort of standard or something? why carnt i just put it in the root.
ASKER
i think this isn't working properly;
<%@ page import="database.*"%>
<%@ page import="database.*"%>
ASKER
to i have to set the tomcat up or anything?
should the classes directory have already been there bacause i had to make it
should the classes directory have already been there bacause i had to make it
>> is this some sort of standard or something?
yes, this is standard.
>> <%@ page import="database.*"%>
<jsp:useBean> doesn't require import.
>> should the classes directory have already been there bacause i had to make it
no, you must create it, open a DOS Windows and check out all the names, all the names are in the right case adn right spelling, for example it's classes, not Classes, not CLASSES.
yes, this is standard.
>> <%@ page import="database.*"%>
<jsp:useBean> doesn't require import.
>> should the classes directory have already been there bacause i had to make it
no, you must create it, open a DOS Windows and check out all the names, all the names are in the right case adn right spelling, for example it's classes, not Classes, not CLASSES.
>> why do i have to put the .class file in the WEB-INF\classes directory is this some sort of standard or something? why carnt i just put it in the root.
Sun's documentation define web app directory structure as following:
"The document root contains a subdirectory called WEB-INF, which contains the following files and directories:
o web.xml - The Web application deployment descriptor
Tag library descriptor files (see Tag Library
Descriptors)
o classes - A directory that contains server-side
classes: servlets, utility classes, and JavaBeans
components
o lib - A directory that contains JAR archives of
libraries (tag libraries and any utility libraries
called by server-side classes)
"
Sun's documentation define web app directory structure as following:
"The document root contains a subdirectory called WEB-INF, which contains the following files and directories:
o web.xml - The Web application deployment descriptor
Tag library descriptor files (see Tag Library
Descriptors)
o classes - A directory that contains server-side
classes: servlets, utility classes, and JavaBeans
components
o lib - A directory that contains JAR archives of
libraries (tag libraries and any utility libraries
called by server-side classes)
"
Are you sure your Bean is correct??
And is the bean in ROOT\WEB-INF\classes\datab ase\ ??
And is the bean in ROOT\WEB-INF\classes\datab
Yeh, I asked same question a few times. even if the bean is not correct, as long as that database directory exist in the right place, he shouldn't see package not found error. I can believe this. :)
ASKER
yeah this is the path cut and pasted from the windows explorer address bar:
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\c lasses\dat abase\Conc .class.
and it looks like this:
package database;
import java.util.*;
import java.sql.*;
import java.sql.DriverManager;
class Conc
{
static Connection conn;
public Conc()
{
try
{
Class.forName("com.mysql.j dbc.Driver ");
}
catch(ClassNotFoundExcepti on e)
{
System.out.println("Could not find Driver");
}
try
{
conn = DriverManager.getConnectio n("jdbc:my sql://cage 08/dantest ?user=root &password= topgun");
}
catch(SQLException e)
{
System.out.println("Could not find Database");
}
testStmt();
login("dan","Dan");
}
public void testStmt()
{
try
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from users");
while(rs.next())
{
for(int j=1;j<=rs.getMetaData().ge tColumnCou nt();j++)
{
System.out.print(rs.getMet aData().ge tColumnLab el(j)+":"+ rs.getObje ct(j)+"\t" );
}
System.out.print("\n");
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public boolean login(String user,String pass)
{
try
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from users where name='"+user+"' and password='"+pass+"'");
while(rs.next())
{
if (rs != null)
{
return true;
}
else
{
return false;
}
}
}
catch(SQLException e)
{
e.printStackTrace();
}
return false;
}
}
this is an exact copy of my jsp file which is in C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT.
<%@ page import="database.*"%>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body>
test
</body>
</html>
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\c
and it looks like this:
package database;
import java.util.*;
import java.sql.*;
import java.sql.DriverManager;
class Conc
{
static Connection conn;
public Conc()
{
try
{
Class.forName("com.mysql.j
}
catch(ClassNotFoundExcepti
{
System.out.println("Could not find Driver");
}
try
{
conn = DriverManager.getConnectio
}
catch(SQLException e)
{
System.out.println("Could not find Database");
}
testStmt();
login("dan","Dan");
}
public void testStmt()
{
try
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from users");
while(rs.next())
{
for(int j=1;j<=rs.getMetaData().ge
{
System.out.print(rs.getMet
}
System.out.print("\n");
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public boolean login(String user,String pass)
{
try
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from users where name='"+user+"' and password='"+pass+"'");
while(rs.next())
{
if (rs != null)
{
return true;
}
else
{
return false;
}
}
}
catch(SQLException e)
{
e.printStackTrace();
}
return false;
}
}
this is an exact copy of my jsp file which is in C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT.
<%@ page import="database.*"%>
<jsp:useBean id="db" scope="session" class="database.Conc"/>
<html>
<body>
test
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
do you still have problem after you add public in front of bean class?
put your database package under ROOT\WEB-INF\classes and restart your server.
NOTE: I saw you gave a lot of 'C' and 'B' grade in your profile. please never give me a 'C' grade, if you don't like my answer please don't accepted it. thank you.