Java Web 求助。帮看看这个验证方法哪里出错了?只有四个不填的时候才正确跳转,别的都是提示成功???
protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServl...
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String email=request.getParameter("email");
String name = request.getParameter("name");
String password=request.getParameter("password");
String regExpression = ("/\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*/");
String mobileNo=request.getParameter("mobileNo");
String regExpression1 = ("/^(86)?((13\\d{9})|(15[0,1,2,3,5,6,7,8,9]\\d{8})|(18[0,5,6,7,8,9]\\d{8}))$/");
String IDCard=request.getParameter("IDCard");
String regIDCard_18 = ("/^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}[\\d|x|X]$/");
String realName=request.getParameter("realName");
String regExpression2 =("/[\\u4E00-\\u9FA5]/");
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
out.println("<html><body>");
if((email!="")||(email==regExpression)||(mobileNo==regExpression1)||(mobileNo!="")||(IDCard==regIDCard_18)||(IDCard!="")||(realName==regExpression2)||(realName!="")){
response.sendRedirect("success.jsp");
}
else{
response.sendRedirect("ZhuCe.jsp");
}
out.println("</body></html>");
} 展开
// TODO Auto-generated method stub
String email=request.getParameter("email");
String name = request.getParameter("name");
String password=request.getParameter("password");
String regExpression = ("/\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*/");
String mobileNo=request.getParameter("mobileNo");
String regExpression1 = ("/^(86)?((13\\d{9})|(15[0,1,2,3,5,6,7,8,9]\\d{8})|(18[0,5,6,7,8,9]\\d{8}))$/");
String IDCard=request.getParameter("IDCard");
String regIDCard_18 = ("/^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}[\\d|x|X]$/");
String realName=request.getParameter("realName");
String regExpression2 =("/[\\u4E00-\\u9FA5]/");
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
out.println("<html><body>");
if((email!="")||(email==regExpression)||(mobileNo==regExpression1)||(mobileNo!="")||(IDCard==regIDCard_18)||(IDCard!="")||(realName==regExpression2)||(realName!="")){
response.sendRedirect("success.jsp");
}
else{
response.sendRedirect("ZhuCe.jsp");
}
out.println("</body></html>");
} 展开
展开全部
用正则表达式。String类中的matches();
if((email!="")||(email==regExpression)||(mobileNo==regExpression1)||(mobileNo!="")||(IDCard==regIDCard_18)||(IDCard!="")||(realName==regExpression2)||(realName!=""))
改成
if((email!="")&& email.matches(regExpression)&& mobileNo.matches(regExpression1)&& mobileNo!="" && IDCard.matches(regIDCard_18) && (IDCard!="") && realName.matches(regExpression2)&& (realName!="")){
还有把正则表达式的匹配串中的开始和结束的‘/’去掉
if((email!="")||(email==regExpression)||(mobileNo==regExpression1)||(mobileNo!="")||(IDCard==regIDCard_18)||(IDCard!="")||(realName==regExpression2)||(realName!=""))
改成
if((email!="")&& email.matches(regExpression)&& mobileNo.matches(regExpression1)&& mobileNo!="" && IDCard.matches(regIDCard_18) && (IDCard!="") && realName.matches(regExpression2)&& (realName!="")){
还有把正则表达式的匹配串中的开始和结束的‘/’去掉
展开全部
if((email!="")||(email==regExpression)||(mobileNo==regExpression1)||(mobileNo!="")||(IDCard==regIDCard_18)||(IDCard!="")||(realName==regExpression2)||(realName!="")){
这里明显应该用&&吧,你注册的要求是满足其中某一个条件就够了?
另外,你的操作都在servlet里进行啊?这应该放在页面上用JS来判断...
这里明显应该用&&吧,你注册的要求是满足其中某一个条件就够了?
另外,你的操作都在servlet里进行啊?这应该放在页面上用JS来判断...
追问
要全部都满足才能提示注册成功。servlet是一个控制器,判断的语句已经在JSP里实现了。问题就出在servlet。但是就不是不知道怎么改
追答
if((email!="")||(email==regExpression)||(mobileNo==regExpression1)||(mobileNo!="")||(IDCard==regIDCard_18)||(IDCard!="")||(realName==regExpression2)||(realName!=""))
改成
if((email!="")&&(email==regExpression)&&(mobileNo==regExpression1)&&(mobileNo!="")&&(IDCard==regIDCard_18)&&(IDCard!="")&&(realName==regExpression2)&&(realName!="")){
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询