File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes how to import class into jsp file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to import class into jsp file" Watch "how to import class into jsp file" New topic

how to import class into jsp file

Linda Xu
Ranch Hand

Joined: Feb 14, 2000
Posts: 51
I compiled a class myClass and saved it into directory:
How can I declare an object of the type myClass in my jsp file.
my jsp file is stored in
Every time,I try to see this myJsp.jsp in browser, I get an error:
unknown type myNode
How to fix this? How to config class path for JSP files?
ruilin yang
Ranch Hand

Joined: Feb 25, 2001
Posts: 334
This is what you need to do:
<%@page import="className.class" %>
You need that double cotation and put the line in the top of the page, but under <%@page language=.... %>
Raj Sharma

Joined: Feb 06, 2001
Posts: 12
You question is a little ambiguous.
If you want to create an instance of your class and use it's method, then other than an import, here is another approach.
Suppose the name of your file is
Then in jsp page if you want to use this class and it's methods, then you should code,
<%OptionValues op = new OptionValues();
op.callMethod(); %>
Between <% and %> you can use any Java code.
Hope it helps.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

You'd still need to import the class. It's not automatically available.

I should also mention that you don't put the .class extension on a page directive import statement, and that multiple imports are separated by commas.

<%@page import="java.util.*,com.yourCompany.yourLibarary.*" %>
[This message has been edited by Mike Curwen (edited May 23, 2001).]
jQuery in Action, 3rd edition
subject: how to import class into jsp file
It's not a secret anymore!