• 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

JSP Displays Source

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all.
I am learning to use Beans with JSP, utilizing Tomcat 3.2.1. To make a long story short, I've modified server.xml to define a new webapp context, and believe I have my files and classes (WEB-INF\classes) in the correct directory sub-structure(s). The problem seems to be that when attempting to use a bean in a JSP, (regardless of scope) the browser returns a source listing of the JSP. I expect I have an ill-typed character in there somewhere, but if so, I haven't been able to locate it. Is there some general mistake I'm making that this problem is symptimatic of that more experienced deveopers might be able to spot (from experience, or course!). When I comment out the bean references int he JSP, the page seems to be otherwise parsed correctly. In attempting to debug this, I haven't seen any material that references this particular problem.
Well, thanks for any insights that can be cast my way.
- Steve
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I comment out the bean references int he JSP, the page seems to be otherwise parsed correctly


Welcome to the Ranch!
It'd be helpful if you could post said offensive bean reference.
hth,
bear
 
S Houde
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Bear,
Thnx for the welcome... its been a while, sorry for the delay here. I'm working thru a book 'JSP Weekend Crash Course', if that helps.
Anyway, below are the html page, JSP page and bean source. To reiterate, the problem is that when submitting the html, which should call the JSP page (includes bean), the result is that the browser just displays the text contents of the JSP page. I'm uising Tomcat 3.2.1, Java 1.3
Anyway here goes...
*** HTML: FruitOrder.html ***
<HTML>
<BODY>
<h2>Fruit Order Form</h2>
Fruit:Mango<br>
Color:Orange<br>
Price PER Pound: $5.95 <br>
<FORM action="confirm.jsp" method="post">
Number of Pounds: <input type="text" name="quantity"><br>
<input type="submit" value="Order Fruit">
</FORM>
</BODY>
</HTML>
*** confirm.jsp ***
<jsp:useBean id="orderedFruit" class="Fruit" />
<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="quantity" param="quantity" />
<HTML>
<BODY>
<h2>Your Fruit Order:</h2>
<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" param="quantity" /><br>
Total: $<%=orderedFruit.getPrice()*orderdedFruit.getQuantityInPounds() %>
<p></p>
<a href="FruitOrder.html">Return to order form to adjust a quantity</a>
</BODY>
</HTML>
*** Fruit.java ***
public class Fruit {

private String fruitName;
private int quantity;
private String color;
private boolean isCitrus;
private float price;
public String getFruitName() { return this.fruitName; }
public void setFruitName(String name) {
this.fruitName = name;
}
public int getQuantityInPounds() { return this.quantity; }
public void setQuantityInPounds(int quantity) {
this.quantity = quantity;
}
public String getColor() { return this.color; }
public void setColor(String color) {
this.color = color;
}
public float getPrice() { return this.price; }
public void setPrice(float price) {
this.price = price;
}
public boolean isCitrus() { return this.isCitrus; }
public void setCitrus(boolean isCitrus) {
this.isCitrus = isCitrus;
}
}
The bean compiles without exception. Apologies for the volume here, but thanks for taking the time to help, and encourage.
Steve
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3.2.1 is a very out of date version of Tomcat. Is there some reason you need to use it?
 
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
Is your JSP located in a directory that the engine will recognize as a "web application" - How about the compiled code for the bean?
It looks to me like you don't have the bean code in a package - this will cause lots of mysterious errors. Put the bean in a package and make sure the compiled class is in the right place under WEB-INF/classes
Be sure to specify the package in the useBean tag and import it in a page tag.
Bill
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic