Link to home
Start Free TrialLog in
Avatar of danBosh
danBoshFlag for United Kingdom of Great Britain and Northern Ireland

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.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
Avatar of kennethxu
kennethxu

>> 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.
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.
Avatar of danBosh

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.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?
can you double check your jsp syntax? are you missing one "="? can you recopy and paster you code here again? thanks.
Avatar of danBosh

ASKER

<%@ 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>
Avatar of danBosh

ASKER

<%@ 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>
Avatar of danBosh

ASKER

<%@ 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>
Avatar of danBosh

ASKER

sorry about that, dont know how it happened
Your first line should be:
<%@ page import="database.*" %>
Your first line should be:
<%@ page import="database.*" %>
Avatar of danBosh

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.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)



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.
Avatar of danBosh

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\classes\database
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.
Avatar of danBosh

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.
Avatar of danBosh

ASKER

i think this isn't working properly;
<%@ page import="database.*"%>
Avatar of danBosh

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
>> 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.
>> 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)
"
Are you sure your Bean is correct??
And is the bean in ROOT\WEB-INF\classes\database\ ??
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. :)
Avatar of danBosh

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\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>





ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
do you still have problem after you add public in front of bean class?