%@ page language="java" pageEncoding="UTF-8"%>
%@ page
import="java.awt.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.util.*" %>
%@ taglib http://struts.apache.org/tags-bean">http://struts.apache.org/tags-bean"
prefix="bean" %>
%@ taglib http://struts.apache.org/tags-html">http://struts.apache.org/tags-html"
prefix="html" %>
%@ taglib http://struts.apache.org/tags-logic">http://struts.apache.org/tags-logic"
prefix="logic" %>
%@ taglib http://struts.apache.org/tags-tiles">http://struts.apache.org/tags-tiles"
prefix="tiles" %>
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
html:html lang="true">
head>
html:base />
title>MyJsp.jsp/title>
meta http-equiv="pragma" content="no-cache">
meta http-equiv="cache-control" content="no-cache">
meta http-equiv="expires" content="0">
meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
meta http-equiv="description" content="This is my page">
!--
link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" >
-->
/head>
body>
h3>在jsp頁面生成驗證碼/h3>
hr/>
%
//out.clear();
//response.setContentType("image/jpeg");//設置響應類型
//response.addHeader("pragma","NO-cache");
//response.addHeader("Cache-Control","no-cache");
//response.addDateHeader("Expries",0);
int width=400, height=30;//圖片的大小(寬和高)
//構架畫布,第一個參數表示畫布的寬,第二個參數表示畫布的高,第三個參數的含義有待確定
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();//實例化畫圖對象
//以下設置背景色
g.setColor(Color.yellow);
Font DeFont=new Font("宋體", Font.ITALIC, 20);
g.setFont(DeFont);
//將已經設置好的背景顏色填充到指定的畫布區域
g.fillRect(0,0, width, height);
//置字體色
g.setColor(Color.blue);
int x=10,y=10,xl=550,yl=15;
g.drawLine(x,y,x+xl,y+yl);
//在畫布中畫橢圓形,參數為橢圓的坐標,用于確定橢圓的大小
g.drawOval(0,10,200,10);
//在畫布上輸出文字信息,第一個參數表示要顯示的文字,第二和第三個參數表示起始點的X、Y坐標
g.drawString("想要輸出的文字-我是陳杉",70,20);
g.dispose();
ServletOutputStream outStream = response.getOutputStream();
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(outStream);
encoder.encode(image);
outStream.close();
%>
/body>
/html:html>