Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

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
0
danBosh
Asked:
danBosh
  • 11
  • 8
  • 5
  • +1
1 Solution
 
kennethxuCommented:
>> 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
 
igor_skCommented:
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
 
danBoshAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
kennethxuCommented:
can you double check your jsp syntax? are you missing one "="? can you recopy and paster you code here again? thanks.
0
 
danBoshAuthor Commented:
<%@ 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
 
danBoshAuthor Commented:
<%@ 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
 
danBoshAuthor Commented:
<%@ 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
 
danBoshAuthor Commented:
sorry about that, dont know how it happened
0
 
igor_skCommented:
Your first line should be:
<%@ page import="database.*" %>
0
 
igor_skCommented:
Your first line should be:
<%@ page import="database.*" %>
0
 
danBoshAuthor Commented:
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
 
igor_skCommented:
Please, tell what files/directories do you have under your application ROOT directory.
0
 
kennethxuCommented:
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
 
danBoshAuthor Commented:
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
 
kennethxuCommented:
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
 
danBoshAuthor Commented:
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
 
danBoshAuthor Commented:
i think this isn't working properly;
<%@ page import="database.*"%>
0
 
danBoshAuthor Commented:
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
 
kennethxuCommented:
>> 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
 
igor_skCommented:
>> 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
 
ScarfishCommented:
Are you sure your Bean is correct??
And is the bean in ROOT\WEB-INF\classes\database\ ??
0
 
kennethxuCommented:
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
 
danBoshAuthor Commented:
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
 
kennethxuCommented:
>> class Conc
change it to:

public class Conc

HTH
0
 
kennethxuCommented:
do you still have problem after you add public in front of bean class?
0

Featured Post

Industry Leaders: 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!

  • 11
  • 8
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now