Java Tutorial/JSTL/Java Beans

Материал из Java эксперт
Перейти к: навигация, поиск

JSTL Working With More Than One Bean

Bid.java



   <source lang="java">

package beans; public class Bid {

   /** Holds value of property price. */
   private long price;
   
   /** Holds value of property item. */
   private String item;
   
   /** Creates a new instance of Bid */
   public Bid() {
   }
   
   /** Getter for property price.
    * @return Value of property price.
    *
    */
   public long getPrice() {
       return this.price;
   }
   
   /** Setter for property price.
    * @param price New value of property price.
    *
    */
   public void setPrice(long price) {
       this.price = price;
   }
   
   /** Getter for property item.
    * @return Value of property item.
    *
    */
   public String getItem() {
       return this.item;
   }
   
   /** Setter for property item.
    * @param item New value of property item.
    *
    */
   public void setItem(String item) {
       this.item = item;
   }
   

}</source>





Set Form Data to Bean and Output

index.jsp



   <source lang="java">

<html>

 <head><title>Create Person</title></head>
 <body>

Enter your details

   <form action="listPageParameters.jsp" method="post">
First name: <input type="text" name="firstName" />
Last name: <input type="text" name="lastName" />
Age: <input type="text" name="age" />
     <input type="submit" value="Submit details" />
   </form>
 </body>

</html></source>





Use Java Bean in JSTL

   <source lang="java">

<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.ru/jstl/core-rt" prefix="c-rt" %> <html>

 <head>
   <title>If Caseless</title>
 </head>
 <body>
   <c:set var="str" value="jStL" />
   <jsp:useBean id="str" type="java.lang.String" />
   <c-rt:if test="<%=str.equalsIgnoreCase("JSTL")%>"> They are
   equal</c-rt:if>
 </body>

</html></source>