Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Location of a Bean

 
Lakshmi Chari
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lakshmi Chari
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic