• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat doesn't see Java bean

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, all. I have a problem where the class "Fruit" isn't being seen. When I call the JSP and it attempts to compile the page, it can't find the class file. I've even placed the class file in the root folder with the html and the jsp page and it still doesn't see it. I was wondering if someone could help me with this? The first line of the JSP page is what's causing the problem.
Thanks,
Donald
<jsp:useBean id="orderedFruit" class="Fruit" /> <------ Error
<jsp:setProperty name="orderedFruit" property="fruitName" value="Mango" />
<jsp:setProperty name="orderedFruit" property="color" value="Orange" />
<jsp:setProperty name="orderedFruit" property="price" value="5.95" />
<jsp:setProperty name="orderedFruit" property="quantityInPounds" param="quantity" />
<HTML>
<body>
<h1>Your Fruit Order</h1>
<br><br>
Fruit: <jsp:getProperty name="orderedFruit" property="fruitName"/><br>
Color: <jsp:getProperty name="orderedFruit" property="color" /><br>
Price: $<jsp:getProperty name="orderedFruit" property="price" /><br>
Quantity: <jsp:getProperty name="orderedFruit" property="quantityInPounds" /><br>
Total:�$<%=orderedFruit.getPrice()*orderedFruit.getQuantityInPounds() %>
<p></p>
<a href="FruitOrder.html">Return to order form to adjust quantity</a>
</body>
</html>

[This message has been edited by Donald Nunn (edited November 27, 2001).]
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the class file in the WEB-INF/class directory. Normal Java package name structuring applies from there.
 
Donald Nunn
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Tim and thanks. When you say Web-Inf class directory do you mean another directory outside of Web-Inf. The reason why I'm asking is once I'm in directory Web-Inf I don't see a classes directory.
Thanks,

------------------
Donald Nunn
Sun Certified Programmer for the Java� 2 Platform
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like Tim says, class files used by JSP go in the same directory as the class files used by servlets - logical since a JSP gets turned into a servlet. If you don't understand this directory structure stuff, download the servlet and JSP API documents from java.sun.com
I strongly advise you to put your bean in a package and recompile, the <jsp:useBean tag MUST have a complete package.classname in the class attribute. If there is no package then Tomcat looks in the "current" directory - guaranteed to not be correct.
Bill
------------------
author of:
 
Donald Nunn
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Bill. That's it. Being a newbie to this JSP/Servlet/Web server world is challenging, however, it's coming together. This particular book that I'm working through, I guess assumes you should know certain details about Apache/Tomcat and it's directory structures and some of the explanations aren't clear, especially regarding beans. So, when you encounter a problem similar to this one it throws you for a loop. Anyway, thanks for your help.

------------------
Donald Nunn
Sun Certified Programmer for the Java� 2 Platform
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The directory structure for a web application (and its equivalent packaged in a WAR file) is a standard for all J2EE compliant platforms whether you're running Tomcat or WebLogic, so it's a good idea to get familiar with it.
 
Donald Nunn
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Tim. I really appreciate the info.

------------------
Donald Nunn
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check if your class is a package first if it is you should put the package name first and add the scope too before the class (i don't think it will matter much.
<jsp:useBean id="orderedFruit" scope="page" class="package.Fruit" />

Originally posted by Donald Nunn:
Hello, all. I have a problem where the class "Fruit" isn't being seen. When I call the JSP and it attempts to compile the page, it can't find the class file. I've even placed the class file in the root folder with the html and the jsp page and it still doesn't see it. I was wondering if someone could help me with this? The first line of the JSP page is what's causing the problem.
Thanks,
Donald
<jsp:useBean id="orderedFruit" class="Fruit" /> <------ Error
<jsp:setProperty name="orderedFruit" property="fruitName" value="Mango" />
<jsp:setProperty name="orderedFruit" property="color" value="Orange" />
<jsp:setProperty name="orderedFruit" property="price" value="5.95" />
<jsp:setProperty name="orderedFruit" property="quantityInPounds" param="quantity" />
<HTML>
<body>
<h1>Your Fruit Order</h1>
<br><br>
Fruit: <jsp:getProperty name="orderedFruit" property="fruitName"/><br>
Color: <jsp:getProperty name="orderedFruit" property="color" /><br>
Price: $<jsp:getProperty name="orderedFruit" property="price" /><br>
Quantity: <jsp:getProperty name="orderedFruit" property="quantityInPounds" /><br>
Total:�$<%=orderedFruit.getPrice()*orderedFruit.getQuantityInPounds() %>
<p></p>
<a href="FruitOrder.html">Return to order form to adjust quantity</a>
</body>
</html>

[This message has been edited by Donald Nunn (edited November 27, 2001).]


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic