?
Solved

jsp and javabean problem

Posted on 2003-03-14
25
Medium Priority
?
295 Views
Last Modified: 2010-04-01
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.JasperException: 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\localhost\_\index_jsp.java:7: package database does not exist
import database.*;
^
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\index_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\localhost\_\index_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\localhost\_\index_jsp.java:48: package database does not exist
            db = (database.Conc) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "database.Conc");
                          ^
4 errors


     at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
     at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
     at org.apache.jasper.compiler.Compiler.generateClass

any idea what i have done wrong
0
Comment
Question by:danBosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 8
  • 5
  • +1
25 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 8138889
>> this page is in my server ROOT and the Conc class is in ROOT\database, but i get this error
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.
0
 
LVL 1

Expert Comment

by:igor_sk
ID: 8138997
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.
0
 

Author Comment

by:danBosh
ID: 8139032
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: /index.jsp(1,19) equal symbol expected
     at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
     at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:428)
     at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:126)
     at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:169)

i did that i i now get this, what does it mean?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:kennethxu
ID: 8139175
can you double check your jsp syntax? are you missing one "="? can you recopy and paster you code here again? thanks.
0
 

Author Comment

by:danBosh
ID: 8139200
<%@ page import="database.*%>
<jsp:useBean id="db" scope="session" class="database.Conc"/>

<html>

<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">

     &nbsp;<p align="center"><b><font face="Arial">User Name:&nbsp;</font></b>&nbsp;&nbsp;

     <input type ="text" name="loginName" size="19"></p>
    <p align="center"><b><font face="Arial">Password:&nbsp;&nbsp;</font></b>&nbsp;&nbsp;
     <input type ="text" name="password" size="19"> </p>
    <p align="center">

     <input type="submit" value="Login"> </p>
</form>

<%
if( (request.getParameter("loginName") != null) && (request.getParameter("password") != null) )
{
        if (true == db.Conc(request.getParameter("loginName"),request.getParameter("password") ))
     {
       
%>
<p align="center">good
<%
    }
     else
     {
%>
bad
<%
     }
}
%> </p>

</body>

</html>
0
 

Author Comment

by:danBosh
ID: 8139213
<%@ page import="database.*%>
<jsp:useBean id="db" scope="session" class="database.Conc"/>

<html>

<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">

     &nbsp;<p align="center"><b><font face="Arial">User Name:&nbsp;</font></b>&nbsp;&nbsp;

     <input type ="text" name="loginName" size="19"></p>
    <p align="center"><b><font face="Arial">Password:&nbsp;&nbsp;</font></b>&nbsp;&nbsp;
     <input type ="text" name="password" size="19"> </p>
    <p align="center">

     <input type="submit" value="Login"> </p>
</form>

<%
if( (request.getParameter("loginName") != null) && (request.getParameter("password") != null) )
{
        if (true == db.Conc(request.getParameter("loginName"),request.getParameter("password") ))
     {
       
%>
<p align="center">good
<%
    }
     else
     {
%>
bad
<%
     }
}
%> </p>

</body>

</html>
0
 

Author Comment

by:danBosh
ID: 8139220
<%@ page import="database.*%>
<jsp:useBean id="db" scope="session" class="database.Conc"/>

<html>

<body bgcolor="#0066FF">
<form action = "index.jsp" method="get">

     &nbsp;<p align="center"><b><font face="Arial">User Name:&nbsp;</font></b>&nbsp;&nbsp;

     <input type ="text" name="loginName" size="19"></p>
    <p align="center"><b><font face="Arial">Password:&nbsp;&nbsp;</font></b>&nbsp;&nbsp;
     <input type ="text" name="password" size="19"> </p>
    <p align="center">

     <input type="submit" value="Login"> </p>
</form>

<%
if( (request.getParameter("loginName") != null) && (request.getParameter("password") != null) )
{
        if (true == db.Conc(request.getParameter("loginName"),request.getParameter("password") ))
     {
       
%>
<p align="center">good
<%
    }
     else
     {
%>
bad
<%
     }
}
%> </p>

</body>

</html>
0
 

Author Comment

by:danBosh
ID: 8139222
sorry about that, dont know how it happened
0
 
LVL 1

Expert Comment

by:igor_sk
ID: 8139231
Your first line should be:
<%@ page import="database.*" %>
0
 
LVL 1

Expert Comment

by:igor_sk
ID: 8139244
Your first line should be:
<%@ page import="database.*" %>
0
 

Author Comment

by:danBosh
ID: 8139247
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.JasperException: 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\localhost\_\index_jsp.java:7: package database does not exist
import database.*;
^
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\index_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\localhost\_\index_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\localhost\_\index_jsp.java:48: package database does not exist
            db = (database.Conc) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "database.Conc");
                          ^
4 errors


     at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
     at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)



0
 
LVL 1

Expert Comment

by:igor_sk
ID: 8139337
Please, tell what files/directories do you have under your application ROOT directory.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8139391
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.
0
 

Author Comment

by:danBosh
ID: 8139497
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\classes\database
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8139738
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.
0
 

Author Comment

by:danBosh
ID: 8139827
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.
0
 

Author Comment

by:danBosh
ID: 8139865
i think this isn't working properly;
<%@ page import="database.*"%>
0
 

Author Comment

by:danBosh
ID: 8139887
to i have to set the tomcat up or anything?

should the classes directory have already been there bacause i had to make it
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8140045
>> 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.
0
 
LVL 1

Expert Comment

by:igor_sk
ID: 8140048
>> 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)
"
0
 

Expert Comment

by:Scarfish
ID: 8140417
Are you sure your Bean is correct??
And is the bean in ROOT\WEB-INF\classes\database\ ??
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8140664
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. :)
0
 

Author Comment

by:danBosh
ID: 8142466
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\classes\database\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.jdbc.Driver");
               
          }    
          catch(ClassNotFoundException e)
          {
         
               System.out.println("Could not find Driver");
          }
         
          try
          {
               conn = DriverManager.getConnection("jdbc:mysql://cage08/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().getColumnCount();j++)
                    {
                   
                         System.out.print(rs.getMetaData().getColumnLabel(j)+":"+rs.getObject(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>





0
 
LVL 14

Accepted Solution

by:
kennethxu earned 140 total points
ID: 8142716
>> class Conc
change it to:

public class Conc

HTH
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8162916
do you still have problem after you add public in front of bean class?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question