JSP basics: import a Java class for use in a JSP

Contributor Icon Contributed by qmchenry  
Tag Icon Tagged: JSP programming  

Importing Java classes enables the use of that class without using the fully qualified class name. Java classes can also be imported into JSPs with page directives.


To import the Java class java.util.Calendar for use in a JSP, use one of the following:

<%@page import="java.util.Calendar"%>

 

6 Comments -


  1. 102 said on November 27, 2008

    thanks a lot :D

  2. george said on April 5, 2009

    If you wrote your own class where do you put it in the file system to access it from JSP?

  3. Anonymous said on June 26, 2009

    If you are using the Apache Tomcat server to serve up your JSP pages, then I would recommend putting your own class packages in ${TOMCAT_BASE}/common/lib/

    For our implementation here, it’s /opt/tomcat5/common/lib/.

    HTH. Enjoy.

  4. Barack said on April 4, 2010

    I don’t know what the problem is (because I’m browsing using Chrome maybe?), but I just see two empty grey ruled-out DIVs below “To import the Java…” .

  5. anonymous said on June 19, 2010

    And yes. It’s because of chrome (i’d that problem too)

  6. CPsychoD said on October 31, 2010

    well, you can just put them in the same folder as the JSP? and also i assume any version is usable, starting from 1.4.2, the hoster probably has the latest version installed right?

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -