• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class object

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys
i m using tomcat 4.0
i hv a simple class
and want to use that class in my JSP programs
i want to create an object of that class in JSP and use methods of the class.
but i dont know in which folder i should keep that class file.
please help me
thanks and regards
Bansal
SCJP2

Tomorrow is two days past the Yesterdays Deadline

 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WEB-INF/classes
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or you can jar it up and put it in WEB-INF/lib ...
 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys this is the simple class I want to use
//class code
import java.sql.*;
public class UserCon
{
Connection con=null;
public Connection returnUserCon(String x)
{
try{
Class.forName"sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:ccrs_mdb");
}catch(Exception e)
{
e.printStackTrace();
}
return con;
}
}
i put the class file in \webapps\examples\WEB-INF\classes folder
but when i run the JSP the error message comes is as below
org.apache.jasper.JasperException: Unable to compile class for JSP..\work\localhost\examples\_0002fccrs_0005fjsp_0002fcusfydate_0002ejspcusfydate_jsp_0.java:21: Class ccrs_0005fjsp.UserCon not found.
UserCon ucon = new UserCon();
after looking at the message i put the class file in \work\localhost\examples\ccrs_0005fjsp folder
but now the error message comes is
org.apache.jasper.JasperException: Unable to compile class for JSPerror: File ..\work\localhost\examples\ccrs_0005fjsp\UserCon.class does not contain type ccrs_0005fjsp.UserCon as expected, but type UserCon. Please remove the file, or make sure it appears in the correct subdirectory of the class path.
..\work\localhost\examples\_0002fccrs_0005fjsp_0002fcusfydate_0002ejspcusfydate_jsp_0.java:21: Class ccrs_0005fjsp.UserCon not found.
UserCon ucon = new UserCon();
please suggest me where should i keep the class file or where i hv to make changes
this was the sample class, like this I hv to actually use some other classes.
thanks and regards
Bansal
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First tell me are u using a war file.If u r using a war file then u have to put your class file in classes directory.Otherwise atleast take precauion to put your classfile in tomcat classpath by editing either tomcat.bat or tomcat.sh file
 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no i m not using war file
and i put the class file in \lib folder
this folder i think is always in clas path
but same error comes
org.apache.jasper.JasperException: Unable to compile class for JSP..\work\localhost\examples\_0002fccrs_0005fjsp_0002fcusfydate_0002ejspcusfydate_jsp_7.java:20: Class ccrs_0005fjsp.UserCon not found.
UserCon ucon = new UserCon();

i dont know why it is looking for this ccrs_0005fjsp folder

Bansal
[ February 26, 2002: Message edited by: Sunil K Bansal ]
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a bug in JSP when trying to use a jsp:bean that is in the default package (you don't put the class in a package) Add the package statement to your class
package db;
...
Put the resultant class file in
/WEB-INF/classes/db
And add the import statement
<%@ page import="db.*" %>
It should work then. Now, DB Connections are expensive in time and network traffic. Try using a pool such as DbConnctionBroker
 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Carl Trusiak
yes it is working now...
bye....
Bansal
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic