|
|
Posted on 12/24/2014 2:28:19 AM
|
|
|
|

[mw_shl_code=javascript,true]$(function(){ $("#userName").blur(function() { var value = $("#userName").val(); verifyUserName(value); }); $("#userName").focus(function() { $("#userNameErr").text(""); }); });
function verifyUserName(userName){ var value = $("#userName").val(); $.ajax({ type:"GET", cache:false, async:false, url:"/bookShopping/UserServlet", data:{method:"verifyUserName",userName:value}, dataType:"json", success:function(result){ if(result.ifreg =="true"){ $("#userNameErr").text("This username is registered!") ); } } }); }[/mw_shl_code]
[mw_shl_code=java,true] <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head>
<title>Registration page</title>
<meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script type="text/javascript" src="<c:url value='/jquery/jquery-1.5.1.js'/>"></script> <script type="text/javascript" src="<c:url value='/js/register.js'/>"></script> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> function _hyz() { $("#vCode").attr("src", '<c:url value='/VerifyCodeServlet?'/>' + new Date().getTime());
} </script> </head>
<body> <form action="/bookShopping/UserServlet"> <input type="hidden" name="method" value="register"/> Username<br/> <input id = "userName" name="userName" type="text" value="${formuser.userName }"/><label id = "userNameErr">${errors.loginname }</label><br/> Real name<br/> <input name="trueName" type="text" value="${formuser.trueName }" />${errors.trueName }<br/> Password<br/> <input name="passWord" type="password" value="${formuser.passWord }"/>${errors.loginpass }<br/> Confirm the password<br/> <input name="repassWord" type="password" value="${reloginpass }" />${errors.reloginpass }<br/> City<br/> <input name="city" type="text" value="${formuser.city }"/>${errors.city }<br/> Residential address<br/> <input name="address" type="text" value="${formuser.address }"/>${errors.address }<br/> Zip code<br/> <input name="postcode" type="text" value="${formuser.postcode }" />${errors.postcode }<br/> ID number<br/> <input name="cardno" type="text" value="${formuser.cardno }"/>${errors.cartno }<br/> Types of <br/>documents <input name="cardType" type="text" value="${formuser.cardType }"/>${errors.cardType }<br/> Contact number<br/> <input name="tel" type="text" value="${formuser.tel }"/>${errors.tel }<br/> Email <br/> <input name="email" type="text" value="${formuser.email }"/>${errors.email }<br/> CAPTCHA <br/><img id= "vCode" src="<c:url value='/VerifyCodeServlet'/>">${errors.verifyCode } <label> <a href="javascript:_hyz()" > replace one</a></label><br/> <input name="verifyCode" /><br/> <input name="BtnRegister" type="submit" value="Register" /> <a href= "<c:url value='/index.jsp'/>" > return to the home page</a> </form> </body> </html> [/mw_shl_code]
[mw_shl_code=java,true]/** * AJAX verifies whether the username is registered * @param req * @param resp * @return * @throws ServletException * @throws IOException */ public String verifyUserName(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { boolean b = false; try { int i = userService.verifyUserName(req.getParameter("userName")); if (i==1) { b=true; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Returns data in JSON format //resp.getWriter().print("{\"bool\":\"qqq\"}"); resp.getWriter().print("{\"ifreg\":\""+b+"\"}"); //resp.getWriter().print(b); System.out.println("{\"ifreg\":\""+b+"\"}"); return ""; }[/mw_shl_code]
|
-
1.png
(226.76 KB, Number of downloads: 426)
-
2.png
(85.65 KB, Number of downloads: 428)
-
3.png
(93.44 KB, Number of downloads: 412)
-
4.png
(174.62 KB, Number of downloads: 418)
-
5.png
(77.35 KB, Number of downloads: 412)
-
6.png
(132.41 KB, Number of downloads: 387)
-
7.png
(113.82 KB, Number of downloads: 397)
Previous:struts2 custom time converterNext:struts2 to get the commonly used objects in the servlet
|