Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1020
  • Last Modified:

How to import a class in jsp ?

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> data.java

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

Simple21
0
simple21
Asked:
simple21
  • 2
2 Solutions
 
KarcOriginCommented:
Include this in your JSP page:

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

Your data.java 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="packagename.data.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

Cheers!



0
 
simple21Author Commented:
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.
0
 
KjarrialbertsCommented:
hi,
You should not add the .class to the class name  so it should be:
<jsp:useBean id="rec" class="data" scope="session"/>
0
 
KjarrialbertsCommented:
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"

cheers
  Kjarri
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now