This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Location of a Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Location of a Bean" Watch "Location of a Bean" New topic
Author

Location of a Bean

Lakshmi Chari
Greenhorn

Joined: Nov 10, 2003
Posts: 7
HI all
I have a very basic problem in placing the bean.
As told i have placed my bean in
D:\Chari\Tomcat\ShoppingCart\WEB-INF\classes\com\shoppingcart\user\User.class
and in my JSP program which is in
D:\Chari\Tomcat\ShoppingCart\simple.jsp i have used
<jsp:useBean id="test" scope="session" class="com.shoppingcart.user.User"/>

Even then iam getting the following 3 errors
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 0 in the jsp file: /simple1.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:\Chari\Tomcat\work\Standalone\localhost\ShoppingCart\simple1_jsp.java:42: package com.shoppingcart.user does not exist
com.shoppingcart.user.User test = null;
^
An error occurred at line: 0 in the jsp file: /simple1.jsp
Generated servlet error:
D:\Chari\Tomcat\work\Standalone\localhost\ShoppingCart\simple1_jsp.java:44: package com.shoppingcart.user does not exist
test = (com.shoppingcart.user.User) pageContext.getAttribute("test", PageContext.SESSION_SCOPE);
^
An error occurred at line: 0 in the jsp file: /simple1.jsp
Generated servlet error:
D:\Chari\Tomcat\work\Standalone\localhost\ShoppingCart\simple1_jsp.java:47: package com.shoppingcart.user does not exist
test = (com.shoppingcart.user.User) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "com.shoppingcart.user.User");
^
3 errors
Please help me in the regard.
Thanks a lot in advance
Regards
Chari
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
something doesn't seem right about your package name. please check in User.java the first line which tells which package it belongs to. You should check the cApItAlIsAtIoN in particular. Is User really in another package called user? The directory structure must be exactly the same as the package statement in User.java.


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Lakshmi Chari
Greenhorn

Joined: Nov 10, 2003
Posts: 7
Hi..
Thanks for the reply.Well i have created a context for shopping cart.
Should i create separate class path for this?If so please tell me how it should be done
Cheers
Chari
Lakshmi Chari
Greenhorn

Joined: Nov 10, 2003
Posts: 7
Hi Tim
The first line is
package com.shoppingcart.user;
yea, the User.java is inside a package called user.
Even then iam getting error
Chari
Lakshmi Chari
Greenhorn

Joined: Nov 10, 2003
Posts: 7
The program works well when i place the file in
D:\Chari\Tomcat\webapps\example\jsp\ShoppingCart\simple.jsp and the bean in
D:\Chari\Tomcat\webapps\example\WEB-INF\classes\com\shoppingcart\User.java
I have created a context for shopping cart in D:\Chari\Tomcat\ShoppingCart\jsp\simple.jsp and placed the same bean in
D:\Chari\Tomcat\ShoppingCart\WEB-INF\classes\com\shoppingcart\user.
Iam getting the error stating that its unable to locate the bean.
Can anyone explain what exactly the problem is?
Thanks
Rgds
Chari
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
try tomcat\webapps\ShoppingCart
this is where contexts should be created by default, i presumed you had changed this in tomcat setup. it might not like a context being in the application root
 
jQuery in Action, 2nd edition
 
subject: Location of a Bean
 
Similar Threads
Package not found error in JSP
JSP - Excel using POI
startup.bat stops itself
Bean class not found error...
Tiles package not found