I am getting an error when importing a Package in JSP file saying "Package <name> not found". Why am I getting that error. Actually I worked with the same package in another directory and it was working fine. I copy pasted the "Java" file and the "Package" into a new directory where the JSP file in that new directory is not able to detect the package.
I deleted the package and recompiled the "Java" file to create the package again even that didn't work.
What could be the reason?
Can anyone give me a detailed explanation where I am going wrong or what is the reason?
JSPs don't look in the current directory for Java classes.
The class loadeders in J2EE weabpps look in a specific list of directories for Java classes. Your package directory structure should go under WEB-INF/classes. If you classes are packed in jars, the jar files should go under WEB-INF/lib
You then need to import any classes/packages that you want to use in your JSP. Look up the <%@page import ...%> and the <jsp:useBean /> tags in the JSP spec (link in my signature).
Thanks for your clarifications on the error message.
But I am working with TOMCAT4.1.24. I created a Bean class in WEB-INF/classes "folder" and compiled there itself to create the package. My Bean class name is WBean.java and Package name is WMonitoring
I imported my bean class using
<%@ page import="java.util.*, WMonitoring.*"%> and created Bean instance using:
WBean wb=new WBean();
I got the compilation error :
cannot resolve symbol
symbol : class WBean [javac] location: class org.apache.jsp.WorkDelegation_jsp [javac] WBean wb=new WBean();
Then I tried to create instance using:
WMonitoring.WBean wb=new WBean()
Even then I am getting error
cannot resolve symbol
symbol : class WBean [javac] location: package WorksMonitor [javac] WorksMonitor.WBean wb=new WBean();
Can you clarify this....
I am using the same Bean class in another JSP file in some other Folder, where it is working fine without any changes. I just made a copy of the entire thing and did some modifications to my current JSP.
Joined: Jul 13, 2006
Can anyone clarify my question, why I am getting Package not found error
If, after following Bear's and Satou's suggestions, this is still not working, post the code to your bean (please be sure to use the UBB code tags) and list the exact location of your bean's class file on your file system.
Joined: Jul 13, 2006
This is my code in WBean.java class which I am going to use in my JSP's.
I have created this bean class file in webapps/myProject/WEB-INF/classes folder of Tomcat and compiled it to create package: WMonitoring, upon successful compilation of the "bean" file I got pacakage WMonitoring which is in classes directory.
Path for WMonitoring folder:
When I create instance of the above WBean class in my jsp, as
I am importing the package using tag in my jsp.
I am creating instance of WBean class which is already declared "Public" as:
WBean wb=new WBean(); //I got error here again I tried creating instance of Bean class using
WMonitoring.WBean wb=new WBean(); //even here I am getting error
Given the details above, can anyone clarify me where actually I am going wrong? I am using the same file in another folder and Iam using it without any errors.. [ July 20, 2006: Message edited by: Sree Mami ]
Maybe you should try to rename your package with lowercase WMonitoring -> wmonitoring
Are you under Windows ?
And please clarify this:
I am using the same file in another folder and Iam using it without any errors
Show us what you're doing there. [ July 20, 2006: Message edited by: Satou kurinosuke ]
Joined: Jul 13, 2006
Thanks for your early reply...
As suggested by you, I even tried renaming my package in "lowercase" but still the problem persists. I didn't do any changes to the above "Bean" class but it's all working well in another Folder in which I practice some programs and upon successful compilation there I just dump those files into "myproject" folder where actually all of my files related to my project are stored.
Yes I am using Windows 2000 Server with Tomcat 4.1.24, Internet explorer: 6. What could be the possible error.
I have created this bean class file in webapps/myProject/WEB-INF/classes folder of Tomcat and compiled it to create package: WMonitoring, upon successful compilation of the "bean" file I got pacakage WMonitoring which is in classes directory
From the command prompt traverse to the webapps/myProject/WEB-INF/classes folder and run the following command and post the output:
This will show the contents(and the hierarchy) of your application(just to make sure that the packaging of your application is correct)
Tried your application(just created a sample jsp and a package and class with the same name as yours) on my machine. It worked fine. Then after reading your posts again, this is something that i found:
Shouldnt your WEB-INF directory be directly under either the "Project" folder or "WorksMonitoring" folder? I tried doing the same as you have done, i created a folder under webapps named myProject and inside that i placed WorksMonitoring folder(which contains the WEB-INF folder). Interestingly, the application did *not* even get deployed, because the server could not find the WEB-INF folder, directly under "myProject". Same thing should have happened in your case, the application should not have been deployed and you should have seen 404 error. However as your logs suggest, the application is getting deployed.
Then i tried one more thing. I *copied* the WEB-INF folder present in the webapps/myProject/WorksMonitoring folder and put it in webapps/myProject folder. I then deleted the WMonitoring package from the classes folder present in webapps/myProject/WEB-INF directory. So effectively, i have the following hierarchy in place:
Note that there are 2 WEB-INF folders present at different locations. The WEB-INF which is directly inside the myProject folder does *not* contain the WMonitoring package.
I then tried out the jsp and even i ran into the same package does not exist exception.
Conclusion is that you are having the WEB-INF/classes/WMonitoring/ package at the wrong place. You should have it as: