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返回验证码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php3d按钮,CSS实现3D按钮效果
- 下一篇: php账号密码备忘,WordPress使