您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 验证码(网页中用到的)
  所属分类: Java
  开发工具:
  文件大小: 5kb
  下载次数: 0
  上传时间: 2009-03-21
  提 供 者: u0114*****
 详细说明: package com.hygj.servlet; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; import java.util.Random; import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class GraphicsCodeServlet extends HttpServlet { /** * The doGet method of the servlet.
* * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int width=80; int height=30; response.setContentType("image/jpeg"); OutputStream output=response.getOutputStream(); BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_BGR); Graphics gs=image.getGraphics(); //232,243,255//240,248,255//215,234,255//238,247,255//225,249,255 gs.setColor(new Color(225,249,255)); gs.setFont(new Font("黑体",Font.BOLD,20)); gs.fillRect(0, 0, width, height); //247,247,0//255,136,136//94,0,0//0,255,0//0,128,255//255,128,255//255,0,128//255,157,60//255,87,6//235,240,21 Color[] cor=new Color[10]; cor[0]=new Color(247,247,0); cor[1]=new Color(255,136,136); cor[2]=new Color(94,0,0); cor[3]=new Color(0,255,0); cor[4]=new Color(0,128,255); cor[5]=new Color(255,128,255); cor[6]=new Color(255,0,128); cor[7]=new Color(255,157,60); cor[8]=new Color(255,87,6); cor[9]=new Color(235,240,21); Random ran=new Random(); for(int i=0; i<5; i++) { //gs.setColor(Color.black); gs.setColor(cor[ran.nextInt(10)]); gs.drawString(String.valueOf(ran.nextInt(10)), 12*(i+1), 20); gs.drawLine(ran.nextInt(width), ran.nextInt(height), ran.nextInt(width), ran.nextInt(height)); } gs.dispose(); ImageIO.write(image, "jpeg",output); } /** * The doPost method of the servlet.
* * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: jsp
 输入关键字,在本站1000多万海量源码库中尽情搜索: