<dependency> <groupId>com.google.code.kaptcha</groupId> <artifactId>kaptcha</artifactId> <version>2.3</version> <classifier>jdk15</classifier> </dependency>
<bean id="verifyCodeProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">
<property name="config">
<bean class="com.google.code.kaptcha.util.Config">
<constructor-arg>
<props>
<prop key="kaptcha.border">yes</prop>
<prop key="kaptcha.border.color">105,179,90</prop>
<prop key="kaptcha.border.thickness">1</prop>
<prop key="kaptcha.noise.color">blue</prop>
<prop key="kaptcha.image.width">150</prop>
<prop key="kaptcha.image.height">50</prop>
<prop key="kaptcha.session.key">verifyCode</prop>
<!-- <prop key="kaptcha.textproducer.char.string">0123456789abcdefghijklmnopqrst!@#$%^*</prop> -->
<prop key="kaptcha.textproducer.char.length">4</prop>
<prop key="kaptcha.textproducer.char.space">4</prop>
<prop key="kaptcha.textproducer.font.size">30</prop>
<prop key="kaptcha.textproducer.font.color">blue</prop>
</props>
</constructor-arg>
</bean>
</property>
</bean>
@Controller
public class CommonController {
@Autowired
private Producer verifyCodeProducer;
@RequestMapping(path = "/getVerifyCodeImage", method = RequestMethod.GET)
public void getVerifyCodeImage(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
ResponseUtils.noCache(response);
response.setContentType("image/jpeg");
String capText = verifyCodeProducer.createText();
session.setAttribute(Constants.SESSION_KEY_VERIFY_CODE, capText);
BufferedImage bi = verifyCodeProducer.createImage(capText);
ServletOutputStream out = null;
try {
out = response.getOutputStream();
ImageIO.write(bi, "jpg", out);
out.flush();
} catch (Exception ex) {
LOGGER.error("Failed to produce the verify code image: ", ex);
throw new ServerInternalException("Cannot produce the verify code image.");
} finally {
IOUtils.closeQuietly(out);
}
}
}
<div class="form-group has-feedback">
<span class="glyphicon glyphicon-barcode form-control-feedback"></span>
<input id="verifyCode" name="verifyCode" type="text" maxlength="4" class="form-control" placeholder="<spring:message code='login.label.code' />" />
<div style="height: 1px"></div>
<img src="${pageContext.request.contextPath}/getVerifyCodeImage" id="verifyCodeImage" style="margin-bottom: -3px" />
<a href="#" rel="external nofollow" onclick="changeVerifyCode()"><spring:message code='login.code.tip' /></a>
</div>
function changeVerifyCode() {
$('#verifyCodeImage').hide().attr('src', '${pageContext.request.contextPath}/getVerifyCodeImage?' + Math.floor(Math.random()*100) ).fadeIn();
event.cancelBubble=true;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有