JSP Basics: Import a Java Class for Use in a JSP

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"%>


About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

6 Responses to “JSP Basics: Import a Java Class for Use in a JSP”

  1. November 27, 2008 at 4:51 am, 102 said:

    thanks a lot :D


  2. April 05, 2009 at 12:07 am, george said:

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


    • June 26, 2009 at 7:08 pm, Anonymous said:

      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.


      • October 31, 2010 at 3:27 pm, CPsychoD said:

        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?


  3. April 04, 2010 at 1:54 pm, Barack said:

    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…” .


    • June 19, 2010 at 9:45 am, anonymous said:

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


Leave a Reply