• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to import class into jsp file

 
Linda Xu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I compiled a class myClass and saved it into directory:
C\jrun\servlet
How can I declare an object of the type myClass in my jsp file.
my jsp file is stored in
C:\JRun\jsm-default\services\jws\htdocs\myJsp.jsp
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
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Linda,
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=.... %>
regards
Ruilin
 
Raj Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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 OptionValues.java
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.
Raj
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj,
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic