Java/JSTL/Form TextField
Содержание
JSTL Form Action: Get TextField Value
<source lang="java">
<html>
<head> </head> <body> <form method="POST" action="form2.jsp">
Please Login |
|
User Name |
<input type="text" name="uid" size="20" /> |
Password |
<input type="password" name="pwd" size="20" /> |
<input type="submit" value="Submit" name="action" /> <input type="reset" value="Reset" name="B2" /> |
</form>
Note: you may use any ID/Password, security is not checked.
</body>
</html> /////////////////////////////////////////////////////////// //File: form2.jsp <%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <html>
Welcome back <c:out value="${param.uid}" /> !
</html>
</source>
JSTL Form: Using TextField
<source lang="java">
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <c:if test="${pageContext.request.method=="POST"}">
<c:choose> <c:when test="${param.add!=null}"> <c:if test="${list!=null}"> <c:set var="list" value="${list}," scope="session" /> </c:if> <c:set var="list" value="${list}${param.item}" scope="session" /> </c:when> <c:when test="${param.remove!=null}"> <c:set var="list2" value="" /> <c:forEach var="item" items="${list}"> <c:if test="${item!=param.item}"> <c:if test="${list2!=""}"> <c:set var="list2" value="${list2}," /> </c:if> <c:set var="list2" value="${list2}${item}" /> </c:if> </c:forEach> <c:set var="list" value="${list2}" scope="session" /> <c:remove var="list2" /> </c:when> </c:choose>
</c:if> <html>
<head> <title>Updatable Collections</title> </head> <body>
Updatable Collections |
|
<select NAME="choice" SIZE="5" width="20"> <c:forEach var="item" items="${list}"> <option> <c:out value="${item}" /> </option> </c:forEach> </select> |
Enter a item to add or remove.
|
</body>
</html>
</source>
JSTL Submit Form TextField Action
<source lang="java">
<html>
<head> <title>Page Data Example</title> </head> <body>
First Name |
<input type="text" name="first" size="40" /> |
Last Name |
<input type="text" name="last" size="40" /> |
Address |
<input type="text" name="address" size="40" /> |
City |
<input type="text" name="city" size="20" /> |
State |
<input type="text" name="state" size="20" /> |
ZIP |
<input type="text" name="zip" size="20" /> |
<input type="submit" value="Submit" name="action" /> <input type="reset" value="Reset" name="action" /> |
</body>
</html> /////////////////////////////////////////////////////////////////////////// <%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <html>
<head> <title>Page Data Example</title> </head> <body>
Name |
Value |
<c:out value="${aItem.key}" /> |
<c:forEach var="aValue" items="${aItem.value}"> <c:out value="${aValue}" /> </c:forEach> |
</body>
</html>
</source>
Property Access
<source lang="java">
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <html>
<head> <title>Property Access</title> </head> <body> <c:if test="${pageContext.request.method=="POST"}"> <c:set var="idx" value="name" /> param.name = <c:out value="${param.name}" />
param[name] = <c:out value="${param[idx]}" />
</c:if>
<form method="post">Please enter your name? <input type="text" name="name" /> <input type="Submit" />
</form> </body>
</html>
</source>