aspose file tools*
The moose likes Tomcat and the fly likes Tomcat doesn't see Java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat doesn Watch "Tomcat doesn New topic
Author

Tomcat doesn't see Java bean

Donald Nunn
Ranch Hand

Joined: Nov 11, 2000
Posts: 200
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).]


<b>Donald Nunn</b><br />Sun Certified Programmer for the Java 2 Platform
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16055
    
  21

Put the class file in the WEB-INF/class directory. Normal Java package name structuring applies from there.


Customer surveys are for companies who didn't pay proper attention to begin with.
Donald Nunn
Ranch Hand

Joined: Nov 11, 2000
Posts: 200
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
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

Joined: Nov 11, 2000
Posts: 200
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

Joined: Jun 25, 2001
Posts: 16055
    
  21

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

Joined: Nov 11, 2000
Posts: 200
Thanks, Tim. I really appreciate the info.

------------------
Donald Nunn
Sun Certified Programmer for the Java� 2 Platform
Adam Adams
Ranch Hand

Joined: Nov 28, 2001
Posts: 60
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).]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat doesn't see Java bean