验证码过期(小功能)

作用:模拟获取验证码,10s后,重新获取。未过期前不可重复获取;

 

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
		//获取随机短信  --不使用了
		Random r = new Random();
		StringBuilder sb =  new StringBuilder();
		for(int i=0;i<=5;i++){
		int s = r.nextInt(10);
		sb.append(s);
		}
	
 %>



  
    短信验证码
	
	
	
	
  
  
  
   

短信验证码 倒计时重新获取


短信验证码:


后台随机产生验证码:

 

 

public class SmsService extends HttpServlet {

	private static final long serialVersionUID = 5846536395092919495L;

	@Override
	public void doPost(HttpServletRequest request,HttpServletResponse response)
								throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String param = request.getParameter("method");
		System.out.println("================");
		System.out.println("param="+param);
		System.out.println("================");
		Random r = new Random();
		StringBuilder sb =  new StringBuilder();
		for(int i=0;i<=5;i++){
		int s = r.nextInt(10);
		sb.append(s);
		}
		System.out.println("短信验证码 :"+sb);
		PrintWriter pw = response.getWriter();
		pw.write(sb.toString());
		pw.flush();
		pw.close();
		
	}

}


效果示意--

 

验证码过期(小功能)_第1张图片验证码过期(小功能)_第2张图片

验证码过期(小功能)_第3张图片

 

 

Java技术圆桌会-微信群,欢迎大家的加入,专注技术讨论和学习。

加入的同学可以先加我微信:luxun758521 备注-圆桌会,然后拉你进群。

你可能感兴趣的:(Jsp/Servlet,js,验证码过期)