• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

connection class

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to use a connection class from my jsp page to avoid call connection from every jsp page.

I am using apache/tomcat. can i keep the class file in the same folder where my jsp resides.

please help me
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.

In a webapplication your classes will go into a folder inside
WEB-INF/classes. (or in a .jar file inside WEB-INF/lib)

Your .jsp (the sources) will not be there, and the compiled versions certainly will not be there.

Herman
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am using apache/tomcat. can i keep the class file in the same folder where my jsp resides.



The usual Tomcat installation includes a class-loader-howto.html file which explains exactly where class files should be placed. Also see the API for details of web application directory structure.

If you are talking about a database connection Tomcat has a facility for maintaining a pool of connections.

Bill
 
author & internet detective
Posts: 42152
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"confused confused",
Please see your Private Messages for an important administrative matter.
 
Preeti Roy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem is not solved. My package is kept in "WEB-INF/classes/connection"
and jsp is kept in same level of folder stucture where WEB-INF is kept.
My error message is "Package connection not found in import"

I am using this syntax to import the package.
<%@page language="java" import="java.sql.*,connection.*" %>

I am using solaris OS with tomcat version 3.2.4.
Can anybody tell me where I am going wrong.

Thanks In Advance
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"confused confused", you have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Be aware that accounts with invalid display names are disabled.

bear
JavaRanch Sheriff
 
Preeti Roy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am really very sorry. And I have changed my Profile name.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can place your class file in folder \WEB-INF\classes\connection in your web application. since the package name is connection.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Preeti,
I think it'll be better if you place all your class files in a package inside the src folder and the jsp files into another in the web folder, and then import all those classes from there into their respective jsp files. Now, you can create a db connection class file and place it in the same package to that of other class files.

Now, in DbConnection.class file,

you can place this code,
public Connection getConn() {
try
{
javax.naming.Context ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("java:/CONPool");
connection = ds.getConnection();
}
catch(Exception ex) {
strErrorMsg = ex.getMessage();
ex.printStackTrace();
}
return connection;
}

CONPool is the pool name that is coming from your ds.xml file.

Import DbConnection in each of the class files for the JSP pages. Create the connection globally inside the class by calling the method getConn() in a costructor, and use it to call your db procedures. Remember to create a method closing the connection at the end of the class file.
You can close the connection by calling this method at the end of its respective jsp file.

Thank You,
Nishant
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Nishant Kr", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
 
Preeti Roy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you All for resonding my problem.
As per the convention I have kept my package in the WEB-INF/classes folder. But still not able to import the PACKAGE. My jsp is saying package not found ti import. Tell me something my i have complied my class jsdk1.4 and in the server my jsdk version is 1.5 . IS there any versiing problem.

I don't want to follow other way apart from package import to access connection class. Can any body post the code where I can include jsp connection file in other file.

Please help me as soon as possible. I am really in trouble.
For Information: OS- solaris 5.10, tomcat -3.2.4, jDk 1.5

thanks in advance
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Preeti Roy:As per the convention I have kept my package in the WEB-INF/classes folder.

Details please.
 
Preeti Roy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
details are as follows

my test.jsp is hosted in /u03/websites/project1 (Apache/tomcat server) version already mentioned.

<%@page language="java" import="com.conn.*,java.sql.*" %>
<%
try{
connect conn= new connect();
Connection con = conn.getConnection();
java.sql.Statement stmt= con.createStatement();
String sql2="select name from table1 where empID ='123'";
ResultSet rs= stmt.executeQuery(sql2);
rs.next();
String ecode=rs.getString("name");
out.println(ecode);
%>
<%
}catch(Exception e){
out.println(e);
}
%>

Java class file is hosted in
/u03/websites/project1/WEB-INF/classes/com/conn/connect.class.

And I am getting thi error.
Package com.conn not found in import.
import com.conn.*;
reply
    Bookmark Topic Watch Topic
  • New Topic