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.
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.
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
Joined: Dec 22, 2003
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.
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