How to import a class in jsp ?

Posted on 2004-11-11
Last Modified: 2008-03-06
Hello Experts;

I have a jsp and a java class. My java class is in the folder of my classes inside the WEB-INF :

MyWeb> WEB-INF> classes>

My jsp is in the main folder of MyWeb. My question is how would I import that class from my
own jsp program ?

Question by:simple21
    LVL 5

    Accepted Solution

    Include this in your JSP page:

    <jsp:useBean id="myData" class="data.class" scope="session"/>

    Your must be compiled and must be in classes directory. If you are using packages then the above statement has to be change accordingly.
    Ex: <jsp:useBean id="myData" class="" scope="session"/>

    After this you can call the data.class methods and property by accessing myData variable. As, myData.yourMethod() Or myData.yourProperty=Value



    Author Comment

    This is what I tried using :

    <jsp:useBean id="rec" class="data.class" scope="session"/>

    Got an error :

    org.apache.jasper.JasperException:  The value for the useBean class attribute data.class is invalid.

    Assisted Solution

    You should not add the .class to the class name  so it should be:
    <jsp:useBean id="rec" class="data" scope="session"/>

    Expert Comment

    hi again,

    If your class is in a package you have to create directory/directories for your class under WEB-INF and put your class under there, and then you have to call it having the class tag in useBean as  class="mypackage.MyClass"


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Title # Comments Views Activity
    Jquery ajax file upload not working 11 125
    attribute vs parameter and setter vs add method 17 79
    bean mapper frameworks 5 54
    java operators 3 70
    If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
    Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now