%@ 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頁面生成驗(yàn)證碼/h3>
hr/>
%
//out.clear();
//response.setContentType("image/jpeg");//設(shè)置響應(yīng)類型
//response.addHeader("pragma","NO-cache");
//response.addHeader("Cache-Control","no-cache");
//response.addDateHeader("Expries",0);
int width=400, height=30;//圖片的大小(寬和高)
//構(gòu)架畫布,第一個參數(shù)表示畫布的寬,第二個參數(shù)表示畫布的高,第三個參數(shù)的含義有待確定
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();//實(shí)例化畫圖對象
//以下設(shè)置背景色
g.setColor(Color.yellow);
Font DeFont=new Font("宋體", Font.ITALIC, 20);
g.setFont(DeFont);
//將已經(jīng)設(shè)置好的背景顏色填充到指定的畫布區(qū)域
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);
//在畫布中畫橢圓形,參數(shù)為橢圓的坐標(biāo),用于確定橢圓的大小
g.drawOval(0,10,200,10);
//在畫布上輸出文字信息,第一個參數(shù)表示要顯示的文字,第二和第三個參數(shù)表示起始點(diǎn)的X、Y坐標(biāo)
g.drawString("想要輸出的文字-我是陳杉",70,20);
g.dispose();
ServletOutputStream outStream = response.getOutputStream();
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(outStream);
encoder.encode(image);
outStream.close();
%>
/body>
/html:html>
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接