欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

java des验证码,Servlet返回验证码

发布时间:2025/4/16 编程问答 107 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java des验证码,Servlet返回验证码 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

Web.xml文件

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

This is the description of my J2EE component

This is the display name of my J2EE component

GetCheckCode

GetCheckCode

GetCheckCode

/checkcode

index.jsp

Servlet文件

import java.awt.Graphics;

import java.awt.image.BufferedImage;

import java.io.IOException;

import java.io.OutputStream;

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 GetCheckCode extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

doPost(request, response);

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("image/JPEG");

int width=80;

int height=15;

BufferedImage bi=new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);

Graphics g=bi.getGraphics();

g.drawString("hello",15,9);

g.dispose();

OutputStream os=response.getOutputStream();

ImageIO.write(bi, "JPEG",os);

os.flush();

os.close();

}

}

原文:http://www.cnblogs.com/gdds/p/3836593.html

总结

以上是生活随笔为你收集整理的java des验证码,Servlet返回验证码的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。