阅读背景:

java生成验证码并可刷新

来源:互联网 

手心创建一个简单的页面来显示所创建的验证码

<body>
  		<form action="loginName.mvc" method="post">
	  		用户名:<input type="text" name="name" id="name"/><br/>
	  		密码:<input type="password" name="password"  id="password"/><br/>
	  		验证码1:<a href="/go.html?url=javascript:changePicture1();" title='看不清楚,换个图片'><img id="checkcode1"  src=""><a href="/go.html?url=javascript:changePicture1();" class="login-text03" title='看不清楚,换个图片'>看不清楚,换个图片</a><br/>
	  		验证码2:<a href="/go.html?url=javascript:changePicture2();" title='看不清楚,换个图片'><img id="checkcode2"  src=""><a href="/go.html?url=javascript:changePicture2();" class="login-text03" title='看不清楚,换个图片'>看不清楚,换个图片</a><br/>
	  		验证码3:<a href="/go.html?url=javascript:changePicture3();" title='看不清楚,换个图片'><img id="checkcode3"  src=""><a href="/go.html?url=javascript:changePicture3();" class="login-text03" title='看不清楚,换个图片'>看不清楚,换个图片</a>
	  		<span id="spantext"></span><br/>
	  		<!--  <input type="button" value="登录" onclick="loginPerson()"/>-->
	  		<input type="submit" value="登录"/>
  		</form>
  </body>
  <script language="javascript">
  	window.onload=function(){
  		changePicture1();
  		changePicture2();
  		changePicture3();
  	};
  	
  	function changePicture1(){
  		$("#checkcode1").attr("src","servlet/CheckCode?code="+Math.random());
  	}
  	function changePicture2(){
  		/* var arry=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
  		         "R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"];
  		var len=arry.length;
  		var code="";
  		for(i=0;i<=4;i++){
  			var index=Math.floor(Math.random()*len);
  			code+=arry[index];
  		} */
  		//alert(code);
  		$("#checkcode2").attr("src","servlet/ImageServlet?code="+Math.random());
  	}
  	function changePicture3(){
  		$("#checkcode3").attr("src","servlet/graphicsImage?code="+Math.random());
  	}
  	function loginPerson(){
  		var name=document.getElementById("name").value;
  		var password=document.getElementById("password").value;
  		if(name==""||password==""){
  		    alert("账户名或密码不能为空");
  			$("#spantext").html("账户名或密码不能为空");
  		}else{
  			$.ajax({
  				type : "post",
  				url : "./loginName.mvc?name="+name+"&password="+password,
  				success : function(data){
  					alert(data);
  					var obj=eval("("+data+")");
  					var message=obj.code;
  					//var name=obj.name;
  					//var password=obj.password;
  					alert(message);
  					//alert(name);
  					//alert(password);
  				},
  				error : function(data){
  					$("#spantext").html("网络错误");
  				}
  			});
  		}
  	}
  </script>
<body>
  		<form ac



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: