importing self created classes

[nobr]Hi I'm making a simple .jsp page which queries a database and then returns results in another html page. I am using a few of my own self defined classes to make the page but I don't know how to import them... there aren't any problems with my classes because they work on a servlet I am using.

I think there might also be some problems with my syntax... any help is appreciated.

the root to my classes is:

C:\Prg\Apache\Tomcat5.5.17\webapps\a4020_28503_BMF

and here is my BooksFinder.jsp

--

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<%@

page language ="java"

import ="java.util.*, webapps.a4020_28503_BMF.WEB-INF.classes.*"

session ="true"

%>

<html xmlns ="http://www.w3.org/1999/xhtml">

<head>

<title>Book List</title>

</head>

<body>

<%

String title = request.getParameter("title");

BookAccessor accessor =new BookAccessor();

BookBean currentBook;

ArrayList myBooks =new ArrayList();

myList = accessor.selectBooksByTitleLike(title);

List titles = myList;

Iterator iterator = titles.iterator();

while (iterator.hasNext() )

{

currentBook = (BookBean) iterator.next();

%>

< a href ="displayBook?ID=<%= currentBook.getBookID() %>" >

<% = currentBook.getTitle() +", " +

currentBook.getPublisher() +"," +

currentBook.getPrice() +"e" %>

</a><br />

<%

}

%>

</body>

</html>

--

The HTML page which calls BooksFinder.jsp is bookSearch2.html:

-

<html xmlns ="http://www.w3.org/1999/xhtml">

<head>

<title>book database</title>

<script language ="JavaScript">

function submitToServer (btnAction)

{

update.regAction.value = btnAction ;

update.submit() ;

}

</script>

</head>

<body>

<form name="update" method ="get" action ="BooksFinder.jsp" target="_blank">

<label>Book Title:

<input name ="title" type ="text" size ="25" maxlength ="30" />

</label>

<input type ="submit" name ="btnSelect" id ="btnSelect"

value ="SELECT" onClick="submitToServer('select');"/>

<input type="hidden" value="" name="regAction" id="regAction"/>

</form>

</body>

</html>

-

thanks I have been trying hard to figure out how to do this and don't know what to fix :(

Message was edited by:

kidMetropolis[/nobr]

[3962 byte] By [kidMetropolisa] at [2007-10-3 1:06:32]
# 1

First of all the classes you write have to be in a package. That's a Java rule, you can't import a class that isn't in a package. So suppose your class is named BookAccessor and you put it in the org.whatever package. Then your WEB-INF/classes directory has to have a subdirectory named "org", and that has to have a subdirectory named "whatever", and in there you put your BookAccessor.class file. And your JSP import would look like this:<%@

page language = "java"

import = "java.util.*, org.whatever.*"

session = "true"

%>

DrClapa at 2007-7-14 18:03:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
As says DrClap, its a must, that you classes be in a package.The right way to import them, (once they are in a package) is with a JSP directive like the following:<%@page import="java.util.*" %><%@page import="mypackage1.*" %>etc
fggarciaa at 2007-7-14 18:03:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
so to make a package I just have to create a directory in my classes directory and then call it... ok I'm going to give it a try.
kidMetropolisa at 2007-7-14 18:03:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Don't forget the package statement at the top of your java sourcefiles.
gimbal2a at 2007-7-14 18:03:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...