预览加载中,请您耐心等待几秒...
1/5
2/5
3/5
4/5
5/5

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

Patchca简单而功能强大 Jar包下载:http://patchca.googlecode.com/files/patchca-0.5.0.zip 源代码:http://patchca.googlecode.com/svn/trunk/ 一:定义一个servlet生成图片(先引入jar包) :配置xml <servlet> <servlet-name>patchca</servlet-name> <servlet-class>com.ssh.servlet.CaptchaServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>patchca</servlet-name> <url-pattern>/patchca.png</url-pattern> </servlet-mapping> :servlet(自定义CaptchaService) publicclassCaptchaServletextendsHttpServlet{ privatestaticfinallongserialVersionUID=4968328161261528097L; privatestaticMyCaptchaServicecs=null; @Override publicvoidinit()throwsServletException{ super.init(); //可直接使用ConfigurableCaptchaService,然后修改配置 cs=newMyCaptchaService(); } @Override publicvoiddestroy(){ cs=null; super.destroy(); } publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse) throwsServletException,IOException{ response.setContentType("image/png"); response.setHeader("cache","no-cache"); HttpSessionsession=request.getSession(true); OutputStreamos=response.getOutputStream(); Stringpatchca=EncoderHelper.getChallangeAndWriteImage(cs,"png",os); session.setAttribute("PATCHCA",patchca); os.flush(); os.close(); } publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse) throwsServletException,IOException{ this.doGet(request,response); } privateclassMyCaptchaServiceextendsAbstractCaptchaService{ publicMyCaptchaService(){ //文本内容 wordFactory=newMyWordFactory(); //字体 fontFactory=newRandomFontFactory(); //效果 textRenderer=newBestFitTextRenderer(); //背景 backgroundFactory=newSingleColorBackgroundFactory(); //字体颜色 colorFactory=newSingleColorFactory(newColor(25,60,170)); //样式(曲线波纹加干扰线) filterFactory=newCurvesRippleFilterFactory(colorFactory); //图片长宽 width=150; height=50; } } privateclassMyWordFactoryextendsRandomWordFactory{ publicMyWordFactory(){ //文本范围和长度 characters="absdekmnowx23456789"; minLength=5; maxLength=4; }