- 浏览: 268376 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (251)
- 面试基础 (9)
- java基础 (40)
- 调试配置 (10)
- 转载文章 (4)
- 心灵鸡汤 (8)
- java工具 (6)
- CSS学习 (7)
- css案例 (2)
- 经济 (1)
- 小节惹的祸 (1)
- 实例心得 (21)
- 数据库 (7)
- 有用的代码 (17)
- Struts (3)
- Hibernate (5)
- Spring (3)
- java xml (7)
- Java Reflection API (1)
- 网络配置 (4)
- SSH (8)
- java开源框架 (13)
- ajax (4)
- swing (1)
- 设计模式 (1)
- 未主流组件 (7)
- WebService (6)
- 20111019 (1)
- xiao清讲课笔笔~~~UML (0)
- 笔记 (2)
- SOAP (9)
- 第一天遇到的问题 (1)
- Java Card (3)
- 面试 (18)
- Java (17)
- JNLP 集群 (0)
- java 面试 (3)
最新评论
-
ap0406708:
138XXXXXXXX
webserivce spring-ws 安全 -
yezhuzhe:
...
[code]SSH上传下载 ------温故知新 -
thinking_ou:
怎么需要解压密码
webserivce spring-ws 安全 -
ap0406708:
uuu999ggg 写道连return都写错了
try catch finally 块 与 函数的return -
wst0350:
...
java正则表达式,js正则表达式
因为做的是wap端的网站,所以不能用到js,所以验证的工作就要放在服务器端,太麻烦了.
regedit.jsp页面
处理的servlet.
工具类
思路是servlet传参数回表单页面,控制错误信息的显示.
regedit.jsp页面
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/> <title>注册页面</title> <jsp:include page="include/css.jsp" flush="true" /> </head> <body> <jsp:include page="include/head2.jsp" flush="true" /> <form action="<%=basePath%>servlet/GetCheckno"> <div> 手机号:<br/> <c:choose> <c:when test="${mobno2==1}"> <span style="color:red;"><b>手机号码格式不正确</b></span><br/> </c:when> <c:when test="${mobno2==3}"> <span style="color:red;"><b>注册手机不能为空</b></span><br/> </c:when> </c:choose> <input type="text" name="mobile" value="" /><br/> <input class="submit" type="submit" value="获取验证码" /> </div> </form> <form action="<%=basePath%>servlet/RegeditServlet" method=post> <div> 用户名:<br/> <c:choose> <c:when test="${userno==1}"> <span style="color:red;"><b>会员名在5-20个字符内,仅可由中英文、数字、下划线组成</b></span><br/> </c:when> <c:when test="${userno==2}"> <span style="color:red;"><b>该用户名已经存在</b></span><br/> </c:when> <c:when test="${userno==3}"> <span style="color:red;"><b>用户名不能为空</b></span><br/> </c:when> </c:choose> <input type="text" name="username" value="" /><br/> 用户密码:<br/> <c:choose> <c:when test="${psw1no==1}"> <span style="color:red;"><b>密码最少不能少于6位字符</b></span><br/> </c:when> <c:when test="${psw1no==3}"> <span style="color:red;"><b>密码不能为空</b></span><br/> </c:when> </c:choose> <input type="password" name="password" value="" /><br/> 确认密码:<br/> <c:choose> <c:when test="${psw2no==1}"> <span style="color:red;"><b>两次输入的密码不相同</b></span><br/> </c:when> <c:when test="${psw2no==3}"> <span style="color:red;"><b>确认密码不能为空</b></span><br/> </c:when> </c:choose> <input type="password" name="password2" value="" /><br/> 注册手机:<br/> <c:choose> <c:when test="${mobno==1}"> <span style="color:red;"><b>手机号码格式不正确</b></span><br/> </c:when> <c:when test="${mobno==3}"> <span style="color:red;"><b>注册手机不能为空</b></span><br/> </c:when> </c:choose> <input type="text" name="mobile" value="" /><br/> 验证码:<br/> <c:choose> <c:when test="${chkno==1}"> <span style="color:red;"><b>验证码格式不正确</b></span><br/> </c:when> <c:when test="${chkno==3}"> <span style="color:red;"><b>验证码不能为空</b></span><br/> </c:when> </c:choose> <input type="text" name="checkno" value="" /><br/> 注册邮箱:<br/> <c:choose> <c:when test="${email==1}"> <span style="color:red;"><b>邮箱格式不正确</b></span><br/> </c:when> <c:when test="${email==3}"> <span style="color:red;"><b>邮箱不能为空</b></span><br/> </c:when> </c:choose> <input type="text" name="email" value="" /><br/> <a href="<%=basePath%>servlet/ShowGreetMent">阅读服务协议</a><br/> <input class="submit" type="submit" value="同意并注册" /> </div> </form> <jsp:include page="include/foot.jsp" flush="true" /> </body> </html>
处理的servlet.
package com.mobile.web.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.MDC; import com.mobile.dao.jdbc.AccountDaoJdbc; import com.mobile.dao.jdbc.ChecknoJdbc; import com.mobile.object.Account; import com.mobile.service.impl.AccountManagerImpl; import com.zhao.util.UtilBean; public class RegeditServlet extends HttpServlet { private Log logger = LogFactory.getLog(this.getClass());//日志操作 private AccountDaoJdbc accountj; private ChecknoJdbc checkj; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } /* public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean flat = true; int fail = 0; String mobile = request.getParameter("mobile"); String checkno = request.getParameter("checkno"); String username = request.getParameter("username"); String password = request.getParameter("password"); String password2 = request.getParameter("password2"); String email = request.getParameter("email"); String checknoSystem = checkj.getCheckno(mobile); String address="/RegeditSuccess.jsp"; if(checkno.equals(checknoSystem)&&password.equals(password2)) { Account account = new Account(); account.setMob(mobile); account.setUser(username); account.setPsw(password); account.setEmail(email); accountj.create(account); } else { address = "/RegeditFail.jsp"; if(!password.equals(password2)){ fail=1;//两次密码不同 address=address+"?fail=1"; } else if(!checkno.equals(checknoSystem)) { fail=2;//验证密不对 address=address+"?fail=2"; } } RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); } */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MDC.put("method", "用户操作");//日志操作 String address="/RegeditSuccess.jsp"; boolean flat = true; int userno = 0; int psw1no =0 ; int psw2no =0; int mobno =0; int chkno =0; int emailno =0; String mobile = request.getParameter("mobile"); String checkno = request.getParameter("checkno"); String username = request.getParameter("username"); String password = request.getParameter("password"); String password2 = request.getParameter("password2"); String email = request.getParameter("email"); if(username.equals("")||username==null) { userno=3; flat=false; } else { if(!UtilBean.checkUser(username)) { userno=1; flat = false; } if(!AccountDaoJdbc.checkAccount(username)) { userno=2; flat = false; } } if(password.equals("")||password==null) { psw1no=3; flat = false; } else { if(!UtilBean.checkPsw(password)) { psw1no=1; flat = false; } } if(password2.equals("")||password2==null) { psw2no=3; flat = false; } else { if(!password.equals(password2)) { psw2no=1; flat = false; } } if(mobile.equals("")||mobile==null) { mobno=3; flat = false; } else { if(!UtilBean.checkMobile(mobile)) { mobno=1; flat = false; } } if(checkno.equals("")||checkno==null) { chkno=3; flat = false; } else { String checknoSystem = checkj.getCheckno(mobile); if(!checkno.equals(checknoSystem)) { chkno=1; flat = false; } } if(email.equals("")||email==null) { emailno=3; flat = false; } else { if(!UtilBean.checkEmail(email)) { emailno=1; flat = false; } } //System.out.println(emailno); if(flat==true) { Account account = new Account(); account.setMob(mobile); account.setUser(username); account.setPsw(password); account.setEmail(email); accountj.create(account); MDC.put("username",username);//日志操作 MDC.put("ip","127.0.0.1");//日志操作 MDC.put("system", "前台WAP端");//日志操作 logger.info("用户:"+username+"注册");//日志操作 address="/RegeditSuccess.jsp"; } else { address = "/regedit.jsp"; request.setAttribute("userno", userno); request.setAttribute("psw1no", psw1no); request.setAttribute("psw2no", psw2no); request.setAttribute("mobno", mobno); request.setAttribute("chkno", chkno); request.setAttribute("emailno", emailno); } RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); } public void init() throws ServletException { accountj = new AccountDaoJdbc(); checkj = new ChecknoJdbc(); } }
工具类
package com.zhao.util; import java.sql.Timestamp; import java.text.DecimalFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Random; import java.util.regex.Matcher; import java.util.regex.Pattern; public class UtilBean { /** * 判断字符串是否是整数 */ public static boolean isInteger(String value) { try { Integer.parseInt(value); return true; } catch (NumberFormatException e) { return false; } } //得到前几天,后几天(月,年)的时间 //年月日标记,正数前几天,负数后几天 public static Timestamp getBeforeTime(int nyr,int nyrNum) { long newlong = System.currentTimeMillis(); Calendar calendar = GregorianCalendar.getInstance(); calendar.setTimeInMillis(newlong); calendar.add(nyr,nyrNum); Timestamp time = new Timestamp(calendar.getTimeInMillis()); //System.out.println(UtilBean.getBeforeTime(Calendar.DAY_OF_MONTH, 100)); //calendar.add(Calendar.MONTH, 1) return time; } public static boolean isFloat(String value) { try { Float.parseFloat(value); return true; } catch (NumberFormatException e) { return false; } } public static String getSixIntStr() { Random r = new Random(); int sint = r.nextInt(1000000); DecimalFormat dfInt=new DecimalFormat("000000"); String str = dfInt.format(sint); return str; } public static boolean regex(String regex, String value) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(value); return m.find(); } public static boolean checkMobile(String value) { //手机号码 String regex = "\\d{11}"; //11位 return regex(regex,value); } public static boolean checkUser2(String value) { String regex = "[a-zA-Z1-9_]{5,20}"; return regex(regex,value); } public static boolean checkUser(String value) { String regex = "\\w{5,20}"; return regex(regex,value); } public static boolean checkEmail(String value) { String regex = "[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+"; return regex(regex,value); } public static boolean checkPsw(String value) { String regex = "\\w{6}"; return regex(regex,value); } public static boolean checkStr(String content,String filter) { //要过虑的字符,用|分隔 Matcher m=Pattern.compile(filter).matcher(content); if(m.find()) { return true; //有非法字符 } else { return false; } } public static boolean checkPostNo(String value) { String regex = "[0-9]{6}"; return regex(regex,value); } public static boolean checkCertificate(String value) { String regex = "^[0-9]{15}$|^[0-9]{18}$"; return regex(regex,value); } public static boolean checkTelno(String value) { //电话 String regex = "^[0-9]{6,20}$"; return regex(regex,value); } public static boolean checkAddress(String value) { //地址 //String regex = "^\\w{1,100}$"; //return regex(regex,value); if(value.length()<100&&value.length()>0) return true; return false; } public static boolean checkPerson(String value) { //String regex = "^\\w{1,20}$"; //return regex(regex,value); if(value.length()<20&&value.length()>0) return true; return false; } public static boolean isFloat2(String value) //价格不超过10位数字(可含两位小数) { String regex ="^[0-9]{1,10}$|^[0-9]{1,9}[.][0-9]{1}$|^[0-9]{1,8}[.][0-9]{1,2}$"; return regex(regex,value); } public static boolean isFloat7(String value) //价格不超过7位数字(可含两位小数) { String regex ="^[0-9]{1,7}$|^[0-9]{1,6}[.][0-9]{1}$|^[0-9]{1,5}[.][0-9]{1,2}$"; return regex(regex,value); } public static boolean String20(String value) { //String regex = "^\\w{1,20}$"; //return regex(regex,value); if(value.length()<20&&value.length()>0) return true; return false; } public static boolean String7int(String value) { //String regex = "^\\w{1,20}$"; //return regex(regex,value); if(value.length()<7&&value.length()>0&&isInteger(value)) return true; return false; } public static boolean String500(String value) { if(value.length()<500&&value.length()>0) return true; return false; } public static boolean String30(String value) { if(value.length()<30&&value.length()>0) return true; return false; } public static boolean checkNum(String value) { String regex = "^[0-9]{1,4}$"; return regex(regex,value); } public static boolean checkskren(String value) //收货人 { //String regex = "^\\w{1,20}$"; //return regex(regex,value); if(value.length()<25&&value.length()>0) return true; return false; } }
思路是servlet传参数回表单页面,控制错误信息的显示.
发表评论
-
好浦的东东
2010-06-18 10:42 582http://grepcode.com/file/repo1. ... -
Excel函数 单元格引用
2010-06-12 13:20 730=SUM(A2:E2) 复制会成 =SUM(A3:E3) ... -
20100601
2010-06-02 08:40 623调试环境tomcat 临时发布 发布tomcat 右键 we ... -
java生成静态页面.
2009-12-07 23:19 1146java生成静态页面. -
2009年10月11月记忆----------java网上商城
2009-12-07 23:01 839果皮网 http://www.guopi.com/ js ... -
2009年3月的记忆-------动漫商城
2009-12-07 22:56 630http://www.cosplay8.cn/ Cospl ... -
MySQL数据类型与Java的类型
2009-12-06 00:48 919mysql 数据类型java类型对照 http://mars ... -
[code] log4j写日志(可以写入数据库)
2009-12-05 12:51 14951.配置可以是properties,xml 2.输出有好多种 ... -
[code]添加,修改,删除后的页面跳转
2009-12-04 14:00 985一,成功确认 1.去到一页面,弹出对话框后,确认跳转. 2.去 ... -
[code]表单验证_3.用框架去验证
2009-12-04 00:17 7971.用Struts验证 struts验证框架开发详解 htt ... -
[code]表单验证_1.用js在客户端验证
2009-12-03 23:29 10371.用js在客户端验证 goodsPublish.jsp页面 ... -
PO BO VO DTO POJO DAO SDO(java的server data object)的疑惑
2009-10-01 17:16 1573PO BO VO DTO POJO DAO概念及其作用(附转换 ... -
[code]9月4号面试要做的guestbook(jsp+servlet+mysql+js)
2009-09-04 15:12 930结构按足 持久层,服务层,web层去写的。 -
[code]SSH 实现注册,登陆,查看,添加,修改,删除
2009-09-03 20:28 25771 mySSH01.rar web.xml是配置了strut ... -
http应答码 500错误 20090812(jsp+servlet+access)Topjoy
2009-08-13 23:21 1661HTTP Status 500 - ----------- ... -
el表达式和jstl标签 20090812(jsp+servlet+access)Topjoy
2009-08-13 21:47 823这两样都是jsp2.0以后自带的 1. <c:if> ... -
servlet+jsp的MVC框架流程 20090812(jsp+servlet+access)Topjoy
2009-08-13 21:31 8831. servlet应答请求--> 调用业务逻辑或数据库 ... -
[code]20090812(jsp+servlet+access)Topjoy 写一网站的流程
2009-08-13 20:47 7301. 需求分析 2. 开发原型(html网页有css.js ... -
20090812(jsp+servlet+access)Topjoy遇到的问题
2009-08-13 20:30 7191. 上传文件 form要是 ENCTYPE="mu ... -
由程序语言的保留字引发的错误
2009-08-13 20:19 6761. String sql = "insert in ...
相关推荐
得到RSA密钥对,产生Signature对象,对用私钥对信息(info)签名,用指定算法产生签名对象,用私钥初始化签名对象,将待签名的数据传送给签名对象(须在初始化之后),用公钥验证签名结果,使用公钥初始化签名对象,用于...
得到RSA密钥对,产生Signature对象,对用私钥对信息(info)签名,用指定算法产生签名对象,用私钥初始化签名对象,将待签名的数据传送给签名对象(须在初始化之后),用公钥验证签名结果,使用公钥初始化签名对象,用于...
1.Web安全性的考虑(表单验证、浏览器Basic方式的验证,应用程序的安全性,SSL,代码考虑) 2.简单介绍您所了解的MVC。 3.简单介绍所了解的XML。 4.文档和编码规范 5.Java中的分页、效率考虑。 6.简单介绍您所...
166、如何用JQuery进行表单验证? 39 167、Prototype如何实现页面局部定时刷新? 40 168、Prototype如何为一个Ajax添加一个参数? 40 169、Ajax请求总共有多少种Callback? 41 170、Javascript如何发送一个Ajax请求?...
答:服务器端向客户端发送一个进程编号,一个程序域编号,以确定对象的位置。 24.在C#中,string str = null 与 string str = “” 请尽量使用文字或图象说明其中的区别。 答:string str = null 是不给他分配...
如果想在正则表达式中使用特殊的标点符号,必须在它们之前加上一个 "\" . 2.字符类 将单独的直接符放进中括号内就可以组合成字符类.一个字符类和它所包含的任何一个字符都匹配,所以正则表达式 / [abc] / 和字母 ...
166、如何用JQuery进行表单验证? 39 167、Prototype如何实现页面局部定时刷新? 40 168、Prototype如何为一个Ajax添加一个参数? 40 169、Ajax请求总共有多少种Callback? 41 170、Javascript如何发送一个Ajax请求?...
PHP是一种易于学习和使用的服务器端脚本语言。只需要很少的编程知识你就能使用PHP建立一个真正交互的WEB站点。本教程并不想让你完全了解这种语言,只是能使你尽快加入开发动态web站点的行列。我假定你有一些HTML...
Server Side ViewState 在服务器端存贮ViewState (ASP.NET 2.0) VS2005 ASP.NET本地化学习笔记&感受 在自定义Server Control中捆绑JS文件 Step by Step 深度解析Asp.Net2.0中的Callback机制 使用 Web 标准生成 ASP...