Java Tutorial/JSTL/Java Beans — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 15:24, 31 мая 2010
JSTL Working With More Than One Bean
Bid.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;
}
}
Set Form Data to Bean and Output
index.jsp
<html>
<head><title>Create Person</title></head>
<body>
<h1>Enter your details</h1>
<form action="listPageParameters.jsp" method="post">
<table>
<tr><td>First name:</td> <td><input type="text" name="firstName" /></td></tr>
<tr><td>Last name:</td> <td><input type="text" name="lastName" /></td></tr>
<tr><td>Age:</td> <td><input type="text" name="age" /></td></tr>
</table>
<input type="submit" value="Submit details" />
</form>
</body>
</html>
Use Java Bean in JSTL
<%@ 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>