Can't import simple class / package into simple JSP page using Apache Tomcat

Can someone walk me through the process of loading a class or package into a JSP using Tomcat?

I think it might be a Tomcat installation issue: S my JSP file is working fine without importing or using dbpool or dbpooljar. I have tried many suggestions for other people similar to questions with no luck. Any help would be appreciated!

My class / package placed in web-inf / classes (among other places)

package dbpooljar;
public class DBPool
{   
   public DBPool()
   {
     System.out.println("dbpool evidence!");
   }
 }

      

My compilation commands

javac "C:\website\apache-tomcat-6.0.18\webapps\ROOT\WEB-INF\classes\dbpool.java"
jar cf "C:\website\apache-tomcat-6.0.18\webapps\ROOT\WEB-INF\classes\dbpooljar.jar" DBPool.java

      

My index.jsp

<%@ page import="java.sql.*,java.util.List,java.util.ArrayList,DBPool" %>

<html>
  <body>
    Getting Length of a String
    <%
        String s1 = "Length of a String!";
        out.println("\"" + s1 + "\"" + " is  of   "  +  s1.length() +   " characters ");
        DBPool test=new DBPool();
    %>
  </body>
</html>

      

And finally my terrible mistake (among other things when I tried different things)

An error occurred at line: 9 in the generated java file
The import DBPool cannot be resolved

      

0


source to share


3 answers


You typed

[% @page import = "java.sql. *, java.util.List, java.util.ArrayList, DBPool "%]

but

package dbpooljar;
public class DBPool { ...

      



Therefore, it should be

[% @page import = "java.sql. *, java.util.List, java.util.ArrayList, dbpooljar.DBPool "%]

plus your java file should be located in a directory named WEB-INF / classes / dbpooljar or if you insist on packing the jar file put the jar file in WEB-INF / lib

Of course the angle brackets "[" and "]" are for the correct xml brackets "<" and ">" - I kept them here to be able to use bold.

+1


source


I don't know about windows, but Linux has a file (/usr/share/tomcat5/conf/jkconfig.manifest) that you can edit to add specific jars to your tomcat executable instance.



0


source


I know this question is old, but I suppose I'll give my answer anyway.

The way Tomcat works, at least your WEB-INF directory should have two folders, one called classes and one called lib. From what I understand, .class files go into WEB-INF / classes and .jar files go into WEB-INF / lib. Also, if you are going to declare your .class file to be in a package, it must be in the appropriate directory; in your case, that means it should be located in WEB-INF / classes / dbpooljar / DBPool.class.

Hope this helps someone.

0


source







All Articles