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

Posted March 11, 2004 by Quinn McHenry in 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"%>


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.

  • 102

    thanks a lot 😀

  • george

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

    • Anonymous

      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.

      • CPsychoD

        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?

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

    • anonymous

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