标签:VerifyCode vc text rootPath verifycode 验证码 切换 getRootPath 图片
<%@ page language="java" contentType="text/html; charset=UTF-8" 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/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <link href="<c:url value='/css/style.css'/>" rel="stylesheet" type="text/css"/> <script type="text/javascript"> //地址获取 function getRootPath(){ var rootPath=window.location.pathname; // /Day517/Ajax.jsp var index = rootPath.indexOf("/",1); rootPath = rootPath.substring(0,index); return rootPath; // /Day517 } </script> </head> <body> <!-- 必须使用post提交 --> <span class="red">${msg }</span> <form action="<c:url value='/login.do'/>" method="post"> <input type="text" name="username"/> <br/> <input type="text" name="password"/> <br/> <input type="text" name="verifycode"/> <br/> <img alt="看不清,换一张" src="<c:url value='/verifycode.do'/>" id="imgcheck" onclick="this.src=getRootPath()+'/verifycode.do?'+Math.random()"/><br/> <input type="submit" value="ok"/> <br/> </form> </body> </html>
@Controller public class VerifyCodeController { @RequestMapping("/verifycode.do") public void doverifycode(HttpServletRequest request,HttpServletResponse response) throws IOException { VerifyCode vc =new VerifyCode(); BufferedImage image = vc.getImage(); String text = vc.getText(); request.getSession().setAttribute("session_verifycode", text); VerifyCode.output(image, response.getOutputStream()); } }
标签:VerifyCode,vc,text,rootPath,verifycode,验证码,切换,getRootPath,图片 来源: https://www.cnblogs.com/19322li/p/11116312.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。