Using servlet classes inside JPS? Plz help!

Hello Java People,

I have a problem that is starting to frustrate me greatly and anyone抯 help would be very appreciated.

My problem is that initially, a website site was developed wholly though servlets. I know this was wrong but hey, its what I have to live with.

I have a main servlet (portal_cgi) that catches all requests. It will then create instances of custom objects such as ONS_Database and a host of other objects we have made and use. All classes/servlets are stored in the web-inf/servlets folder. All servlets and classes can call or create instances of each other. Works great infact!!!!

Enter my JSP problem.

What I need to do is simple. Inside my JPS file, I need to create instances of objects that are stored in my servlet folder. For example

<%

ONS_Database.CarData car =new ONS_Database.CarData();

car.primaryKey =new String(?11?;

%>

Where the ONS_Database class is stored in the web-inf/servlets folder

This command works fine in all of my servlets but I cannot for the life of me import this command into any JPS file. I know its probably a one line <import> command but I simply cannot find it!!!

I understand that the use of Enterprise beans help but don抰 solve my problem. I can get a bean to return an instance of custom objects but whats the point if I cant get my jsp file to access the ONS_Database class to polymorph is back into its correct class?

My question is : How can I initialise and use classes stored in my servlet folder (web-inf/servlets) inside my JPS files?

I have bean (pun intended) searching far and wide and cannot seem to gather the answer to this problem. Lots of information that is similar but not quite solving my problem!

Thanks for the help guys!!!!

Dale M

[1893 byte] By [big_milsya] at [2007-11-27 8:13:43]
# 1
you must import your class with it's full path,like "<%@page import ='packagename.classname' ">if you want to use javabean,you can add<jsp:useBean id='beanname' calss='your_class_path.classname'>
field-zeroa at 2007-7-12 19:58:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

tried this, problem is that my classes are not in a package. For example, if I had the the class myClass in the package myPackage I would type

<%@ page import="myClass.myPackage" %>

in terms of class locations, I would have to create a directory inside the WEB-INF/classes directory called myPackage and put myClass into this directory. This works fine.

Soooooo, how do I use the same import command for importing classes NOT in a package....ie servlets in the WEB-INF/servlets directory?

Thanks for your input tho!!!

big_milsya at 2007-7-12 19:58:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
you may open your web.xml,it's in /WEB-INF,and find your servlet mapping class,such as "<servlet><name></name><class>your_servlet_class_path</class></servlet>",your_servlet_class_path is the correct class-path.hope it'll help u.^ ^
field-zeroa at 2007-7-12 19:58:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hay..,

If u have tried to import a class as you mentioned.., it wont work for sure.

Coz it should be :

<%@ page import="myPackage.myClass" %>

not :

<%@ page import="myClass.myPackage" %>

Hope this helps..

- Asela -

Focuzz@aselaa at 2007-7-12 19:58:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

hehe, yeah that was a typo more than anything else. I will give the web.xml a tweak and see if thsi work but im quite certain it wont as i have already tried this?

Any help on my original question would be awesome! How do I call a class/servlet from a JSP that is NOT in a package but in the default servlet location (web-inf/classes) instead?

Thanks

big_milsya at 2007-7-12 19:58:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

There is no longer any way to import classes that are in the default "unnamed" package.

As of Java1.4 they disabled that functionality as a bug:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4361575

The only solution I can see is to refactor your servlet classes so that they ARE in packages. An IDE like Eclipse has great support for that sort of thing.

Cheers,

evnafets

evnafetsa at 2007-7-12 19:58:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Awesome, thanks evnafets, thats the answer I was looking for.

Yeah, it is possable to package up my 'support' servlets into library classes but will require a fair bit of work to do so. But as long as I know that my initial idea is not possable, im quite happy to do this.

Thanks again.

Dale M

big_milsya at 2007-7-12 19:58:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Yes, thank you for the "Official" answer. That one's "bean" bothering me for awhile now. Thank you also big_milsy for the follow up.
wlbragga at 2007-7-12 19:58:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...