使用JSTL进行页面服务器端校验
2007-05-14 17:06
232 查看
验证JSP(包含用户输入)
验证条件为,姓名和年龄均为必填字段,并且年龄必须大于18岁
<%...@ page contentType="text/html; charset=gb2312" %>
<%...@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%...@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Currency Formatting</title>
</head>
<body>
<c:if test="${param.submitted}">
<c:if test="${empty param.name}" var="noName"/>
<c:if test="${empty param.age}" var="noAge"/>
<c:catch var="errorAge">
<fmt:parseNumber var="paraseAge" value="${param.age}"/>
<c:if test="${paraseAge < 18}" var="youngAge"/>
</c:catch>
<c:if test="${not(noName or noAge or youngAge)}">
<c:set value="${param.name}" var="name" scope="request"></c:set>
<c:set value="${param.age}" var="age" scope="request"></c:set>
<jsp:forward page="result.jsp"></jsp:forward>
</c:if>
</c:if>
<form action="validate.jsp">
<input type="hidden" name="submitted" value="true"/>
输入姓名(必填):<input type="text" name="name"/><br>
<c:if test="${noName}">请输入姓名<br></c:if>
输入年龄(必填,大于18岁)<input type="text" name="age"/><br>
<c:if test="${noAge}">请输入年龄<br></c:if>
<c:if test="${youngAge}">年龄必须大于18<br></c:if>
<input type="submit" value="submit"/>
</form>
</body>
</html>
验证通过后的页面为result.jsp,如果验证不通过,则跳转会原输入页面
验证条件为,姓名和年龄均为必填字段,并且年龄必须大于18岁
<%...@ page contentType="text/html; charset=gb2312" %>
<%...@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%...@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Currency Formatting</title>
</head>
<body>
<c:if test="${param.submitted}">
<c:if test="${empty param.name}" var="noName"/>
<c:if test="${empty param.age}" var="noAge"/>
<c:catch var="errorAge">
<fmt:parseNumber var="paraseAge" value="${param.age}"/>
<c:if test="${paraseAge < 18}" var="youngAge"/>
</c:catch>
<c:if test="${not(noName or noAge or youngAge)}">
<c:set value="${param.name}" var="name" scope="request"></c:set>
<c:set value="${param.age}" var="age" scope="request"></c:set>
<jsp:forward page="result.jsp"></jsp:forward>
</c:if>
</c:if>
<form action="validate.jsp">
<input type="hidden" name="submitted" value="true"/>
输入姓名(必填):<input type="text" name="name"/><br>
<c:if test="${noName}">请输入姓名<br></c:if>
输入年龄(必填,大于18岁)<input type="text" name="age"/><br>
<c:if test="${noAge}">请输入年龄<br></c:if>
<c:if test="${youngAge}">年龄必须大于18<br></c:if>
<input type="submit" value="submit"/>
</form>
</body>
</html>
验证通过后的页面为result.jsp,如果验证不通过,则跳转会原输入页面
相关文章推荐
- JAVA_WEB Struts2学习:使用验证框架进行校验JSP页面元素 反编译工具的配置 Strtuts2 国际化学习
- 使用监听器对Spring bean id进行唯一校验
- struts中根据validation.xml配置文件进行页面输入项的校验
- 如何使用SpringMVC进行数据校验
- springmvc使用JSR-303进行校验
- SpringMVC 使用JSR-303进行校验Bean Validation------分组校验
- SpringMVC 使用JSR-303进行校验 @Valid
- 用户注册:后台数据校验:使用xml进行校验(Struts2)
- 使用ab进行页面的压力测试
- SharePoint服务器端对象模型 之 使用CAML进行数据查询
- 针对ASP.NET页面实时进行GZIP压缩优化的几款压缩模块的使用简介及应用测试!(附源码)
- 使用Ext Viewport进行页面布局时Panel中的sumit按钮无法提交表单数据
- SpringMVC 使用JSR-303进行校验 @Valid
- 实验_使用Struts框架进行数据验证(登陆校验)
- 使用ab进行页面的压力测试
- JavaScript学习——使用JS完成注册页面表单校验
- ASP.NET页面进行GZIP压缩优化的几款压缩模块的使用简介及应用测试!(附源码)第1/2页
- 使用HBulider的二维码功能来进行手机页面的调试
- 使用xmldom在服务器端生成静态html页面
- 关于在页面加载完后使用js修改图片高度进行手机屏幕适配的问题