How do I import my own java packages and classes for use in JSP pages? In what directory should they reside? How do I put them on the CLASSPATH?

Byron Tymvios

If your classes are packaged in a jar file you can put the jar file into the WEB-INF/lib directory of your web application. If you have unpackaged classes you can put them in the WEB-INF/classes directory, however the directory tree under WEB-INF/classes needs to look the same as the class's package. So if your classes package name is com.xyz then the directory structure should look like this web-inf/classes/com/xyz with your classes in the xyz directory.

Once the jar and/or classes are in these directories they will automatically be on the classpath, the container/application server should take care of that.

To import these classes for use in a JSP page you need to use the JSP page directive with the import attribute, and the value of the import attribute should be set to the class or classes you would like to import.

Example:
// To import one class
<%@ page import="com.xyz.MyClass" %>
OR
// To import multiple classes from the com.xyz package
<%@ page import="com.xyz.*" %>

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact