`

Jcore

阅读更多
$(function(){
	new JCore.CheckCode($('#checkCode'),'${base}/CheckCode.svl');
});

<input name="checkCode" type="text" class="input" id="checkCode" size="15"/>
 
@SuppressWarnings("serial")
public class ImageCaptchaServlet extends HttpServlet {
	public static final String CAPTCHA_IMAGE_FORMAT = "jpeg";
	private ImageCaptchaService imageCaptchaService;
	private String beanName = "imageCaptchaService";

	public void init(ServletConfig servletConfig) throws ServletException {
		super.init(servletConfig);
		WebApplicationContext wac = WebApplicationContextUtils
				.getRequiredWebApplicationContext(servletConfig
						.getServletContext());
		imageCaptchaService = (ImageCaptchaService) wac.getBean(beanName,
				ImageCaptchaService.class);
	}

	protected void doGet(HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws ServletException,
			IOException {

		byte[] captchaChallengeAsJpeg = null;
		// the output stream to render the captcha image as jpeg into
		ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
		try {
			// get the session id that will identify the generated captcha.
			// the same id must be used to validate the response, the session id
			// is a good candidate!
			String captchaId = httpServletRequest.getSession().getId();
			// call the ImageCaptchaService getChallenge method
			BufferedImage challenge = imageCaptchaService
					.getImageChallengeForID(captchaId, httpServletRequest
							.getLocale());

			// a jpeg encoder
			ImageIO.write(challenge, CAPTCHA_IMAGE_FORMAT, jpegOutputStream);
		} catch (IllegalArgumentException e) {
			httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
			return;
		} catch (CaptchaServiceException e) {
			httpServletResponse
					.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			return;
		}

		captchaChallengeAsJpeg = jpegOutputStream.toByteArray();

		// flush it in the response
		httpServletResponse.setHeader("Cache-Control", "no-store");
		httpServletResponse.setHeader("Pragma", "no-cache");
		httpServletResponse.setDateHeader("Expires", 0);
		httpServletResponse.setContentType("image/jpeg");
		ServletOutputStream responseOutputStream = httpServletResponse
				.getOutputStream();
		responseOutputStream.write(captchaChallengeAsJpeg);
		responseOutputStream.flush();
		responseOutputStream.close();
	}
}
 
<servlet>
		<servlet-name>jcaptcha</servlet-name>
		<servlet-class>com.mobirit.mtmibp.common.checkcode.ImageCaptchaServlet</servlet-class>
	</servlet>



<servlet-mapping>
		<servlet-name>jcaptcha</servlet-name>
		<url-pattern>/CheckCode.svl</url-pattern>
	</servlet-mapping>
分享到:
评论

相关推荐

    Jcore数据库自动化工具使用手册.doc

    ### Jcore数据库自动化工具使用手册知识点详述 #### 一、前言 Jcore是一款专为数据操作设计的面向对象工具,它简化了Java应用程序与数据库之间的交互过程。相较于其他对象关系映射(ORM)工具,Jcore具备简单、灵活...

    jcore-android-1.2.1.jar_androids_android_

    《JCore-android-1.2.1.jar:Android平台的核心组件解析》 在移动应用开发领域,尤其是在Android系统上,开发者经常会遇到各种第三方库,它们提供了丰富的功能,简化了开发流程。今天我们要深入探讨的是“jcore-...

    jCore 0.9.gz

    jCore是一个网站内容管理系统,主要适合网站管理员使用,基于LAMP环境开发。该系统可以帮助你维护客户的多个网站,并保持网站应用的即时更新和补丁修正。它包含两个子系统,分别是jCore Server和jCore Client。 ...

    PyPI 官网下载 | jcore-0.2.0.524-py3-none-any.whl

    **PyPI 官网下载 | jcore-0.2.0.524-py3-none-any.whl** PyPI(Python Package Index)是Python程序员发布自己开发的库和工具的官方平台,它为全球Python开发者提供了一个共享资源的仓库。在Python开发中,我们经常...

    PyPI 官网下载 | jcore-0.2.0.541-py3-none-any.whl

    《PyPI官网下载:jcore-0.2.0.541-py3-none-any.whl——Python库解析》 PyPI(Python Package Index)是Python社区的主要软件包资源库,它为开发者提供了一个发布、查找和安装Python模块的平台。在Python编程中,...

    cordova-plugin-jcore

    Cordova Plugin JCore极光各种开发者服务的核心依赖 JCore SDK 的 Cordova 插件。极光开发者服务及对应的 Cordova 插件如下:极光推送(JPush)-极光 IM(JMessage)-极光统计(JAnalytics)-极光短信验证码(JSMS)...

    JCore_J-Intergrate_ABAQUS_J积分.zip

    《JCore_J-Intergrate_ABAQUS_J积分:深度解析与应用实践》 在当前的工程模拟领域,ABAQUS作为一款强大的非线性有限元分析软件,被广泛应用于各种复杂工程问题的求解。而J积分,作为断裂力学中的一个重要概念,对于...

    JCore_J-Intergrate_ABAQUS_J积分_源码.zip

    【标题】"JCore_J-Intergrate_ABAQUS_J积分_源码.zip" 提供的是一套用于集成ABAQUS软件的J积分计算工具的源代码。J积分是有限元分析中的一种重要概念,尤其在断裂力学领域,它被广泛应用于裂纹扩展和应力强度因子的...

    jCore CMS系统 v0.9.rar

    jCore 是一个网站内容管理系统,主要适合网站管理员使用,基于 LAMP 环境开发。该系统可以帮助你维护客户的多个网站,并保持网站应用的即时更新和补丁修正。它包含两个子系统,分别是 jCore Server 和 jCore Client ...

    jcore:用于构建UI组件JavaScript库

    核心 用于构建UI组件... class MyComponent extends jCore . Component { constructor ( el ) { super ( el ) ; } } const el = document . getElementById ( 'content' ) ; const c = new MyComponent ( e

    jpush_jar引用资源

    下面将详细阐述JPush的使用、`jcore-android-1.2.3.jar`的作用以及如何在Android项目中正确引用这些资源。 1. **JPush简介** JPush是极光公司提供的移动推送服务,支持Android、iOS和Windows Phone平台。它提供了...

    科尔多瓦-插件-jcore

    Cordova插件JCore 极光各种开发者服务的核心依赖JCore SDK的Cordova插件。 极光开发者服务及对应的Cordova插件如下: 极光推进(JPush) 极光IM(JMessage) 极光统计(JAnalytics) 极光短信验证码(JSMS)-...

    Jcore jquery.rar

    NULL 博文链接:https://mysougou.iteye.com/blog/722012

    jcore javascript的另一个良好工具(有详细中文说明)

    javascript高级程序员 必须掌握的工具集

    jCore PHP版CMS 0.8

    内容索引:PHP源码,CMS系统,jCore jCore 0.8 发布,该版本增加了Template Exporter ,购物订单结算页面,email自动回应等。    jCore 是一个网站内容...它包含两个子系统,分别是 jCore Server 和 jCore Client 。  

    jcore:jCore-极简6kB jQuery克隆

    jCore-极简4kB jQuery克隆Functions:each() - Iterates through every element in the collection of matched elements invoking callback on every one of themon() - Attaches callback function to one or more ...

    完美解决Jpush[获取sdk版本失败!]的问题

    E/JIGUANG-JCore: [JCoreGlobal] Get sdk version fail![获取sdk版本失败!] 05-31 12:47:40.088 23896-23896/? W/System.err: java.lang.UnsatisfiedLinkError: Native method not found: ...

Global site tag (gtag.js) - Google Analytics