| |
24. 15. 4. 解析输入 |
|
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>Parse Number</title>
</head>
<body>
<form method="POST">
<table>
<tr>
<td width="100%" colspan="2">
Number Formatting
</td>
</tr>
<tr>
<td width="47%">Enter a number to be parsed:</td>
<td width="53%">
<input type="text" name="num" size="20" />
</td>
</tr>
<tr>
<td width="100%" colspan="2">
<p align="center">
<input type="submit" value="Submit" name="submit" />
<input type="reset" value="Reset" name="reset" />
</p>
</td>
</tr>
</table>
<P> </p>
</form>
<c:if test="${pageContext.request.method=='POST'}">
<table>
<tr>
<td width="100%" colspan="2">
Formatting: <c:out value="${param.num}" escapeXml="false" />
</td>
</tr>
<tr>
<td width="51%">type="number"</td>
<td width="49%">
<c:catch var="e">
<fmt:parseNumber var="i" type="number" value="${param.num}" />
<c:out value="${i}" escapeXml="false" />
</c:catch>
<c:out value="${e}" escapeXml="false" />
</td>
</tr>
<tr>
<td width="51%">type="currency"</td>
<td width="49%">
<c:catch var="e">
<fmt:parseNumber var="i" type="currency" value="${param.num}" />
<c:out value="${i}" escapeXml="false" />
</c:catch>
<c:out value="${e}" escapeXml="false" />
</td>
</tr>
<tr>
<td width="51%">type="percent"</td>
<td width="49%">
<c:catch var="e">
<fmt:parseNumber var="i" type="percent"
value="${param.num}" />
<c:out value="${i}" escapeXml="false" />
</c:catch>
<c:out value="${e}" escapeXml="false" />
</td>
</tr>
<tr>
<td width="51%">type="number" integerOnly="true"</td>
<td width="49%">
<c:catch var="e">
<fmt:parseNumber var="i" integerOnly="true"
type="number" value="${param.num}" />
<c:out value="${i}" escapeXml="false" />
</c:catch>
<c:out value="${e}" escapeXml="false" />
</td>
</tr>
</table>
</c:if>
</body>
</html>
|
|
Download: JSTLParseValueFromForm.zip( 1,225 k) |
|