aspose file tools*
The moose likes JSP and the fly likes import java file - error in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "import java file - error in JSP" Watch "import java file - error in JSP" New topic
Author

import java file - error in JSP

Amit Delve
Ranch Hand

Joined: Dec 22, 2003
Posts: 33
Hello,
I am using Tomcat for my JSPs.
My jsp pages are present in the tomcat/webapps directory under my application.
The structure of my application is as follows
tomcat
|
webapps
|
myapp
|
jsp - (contains my jsp pages)
|
page1.jsp
page2.jsp
|
classes - (contains my class files)
|
com
|
project
|
javafiles
|
class1.class
class2.class
|
lib - (contains my jar files)
I am trying to import class1.class in my jsp pages eg. page1.jsp.
I use the standard import file syntax in my jsp page -
@import com.project.javafiles.* .
When I do that I get an error stating that file cannot be imported.
Is there anyway i can import my java objects in my JSP and use them as plain java objects without using the usebean directive.
What I mean is can i use normal java code for object instantiation in the jsp page.
Please reply asap.
Thank you very much.
Delve.
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
I'm not sure your directory structure is right. The class files should be under yourApp/WEB-INF/classes and you recreate the package structure as database under that.
[ January 02, 2004: Message edited by: Tim Baker ]

Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Hi Delve,
First, in order for your classes to be in Tomcat�s classpath, you need to use a proper Web Application Directory Structure. They must be in the directory <webapp-root >/WEB-INF/classes (so in your case <webapp-root>/WEB-INF/classes/com.project/javafiles/) and your jars in <webapp-root >/WEB-INF/lib
Take a look at Tomcat's Application Developer's Guide for more info. You can also Google "Web Application Directory Structure".
Once your files are in the correct directores, you can import them in a JSP using the following page directive:

You can then use the classes in scriptlets:

You should note, however, that since JSP v1.2 scriptlet use is discouraged in place of tag libraries, including the JSTL (JSP Standard Tag Library). Scriptlets muddy up the view presentation with business logic. Under a good MVC (Model View Controller) design, the presentation markup (i.e. html) and business logic (java code) should be kept separate.
HTH
Amit Delve
Ranch Hand

Joined: Dec 22, 2003
Posts: 33
Hello All,
Thank you for your reply.
The thing is that the directory structure I mentioned in my previous mail may not be right because I am not infront of my development machine right now.
I am sure my directory structure is right in my development machine because I could use my java class file through the <jsp:usebean> and it worked. But the import would not work.
I even created a .war using the same structure with the jsp and java files having <jsp:usebean> and it worked too.
So I am pretty sure that my directory structure is right because "usebean" is able to load my class properly. It is just that when I am trying to import the class and use it, it fails.
Please do provide feedback.
Thank you,
Delve.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

Welcome to the Ranch Delve!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
JSP Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Delve,
Can you post a copy of the exact error (with a stack trace if applicable) you�re getting. They would probably help us track down your issue.
Amit Delve
Ranch Hand

Joined: Dec 22, 2003
Posts: 33
Hi Mark,
Sure I will do that. I am at a friends place right now. Will do that in a couple of hours. Thank you very much.
Delve.
Amit Delve
Ranch Hand

Joined: Dec 22, 2003
Posts: 33
Hello,
Well I think the import problem got resolved somehow. I am not receiving any errors right now. I dont know how - probably a reboot of the machine solved it , not too sure.
thank you,
Amit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: import java file - error in JSP