<img src="<a href="http://...../getImg">http://...../getImg">
ÔÀí£¬ÔÚservletÖÐËæ»úÉú³ÉÒ»¸ö4λÊý×Ö1000-9999
È»ºó°ÑÕâÊý×ÖдÈësession
Êä³öÒ»¸öͼƬ£¬ÉÏÃæдÓÐÕâËĸöÊý×Ö
ÔÚ·þÎñÆ÷¶Ë¸ù¾ÝÓû§ÊäÈëµÄÊý×ÖºÍ
sessionÖеÄÖµ±È½Ï¡£
package com.schoolwx.util;
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.*;
import java.awt.image.*;
/**
* Title: getImg.java
* Description: Õâ¸öclassÖ÷ҪʵÏÖËæ»úÉú³ÉÒ»¸ö4λÊýµÄÑéÖ¤Â룬²¢Ð´Èësession£¬
* Copyright: Copyright (c) 2003
* Company: À¶ÐÇÈí¼þ
* @author falcon
* @version 1.1
*/
public class getImg extends HttpServlet {
PRivate Font mFont=new Font("ËÎÌå", Font.PLAIN,12);//ÉèÖÃ×ÖÌå
//´¦Àípost
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
doGet(request,response);
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
//È¡µÃÒ»¸ö1000-9999µÄËæ»úÊý
String s="";
int intCount=0;
intCount=(new Random()).nextInt(9999);//
if(intCount<1000)intCount+=1000;
s=intCount+"";
//¶Ôsession¸¶Öµ¡£
HttpSession session=request.getSession (true);
session.setAttribute("getImg",s);
response.setContentType("image/gif");
ServletOutputStream out=response.getOutputStream();
BufferedImage image=new BufferedImage(35,14,BufferedImage.TYPE_INT_RGB);
Graphics gra=image.getGraphics();
//ÉèÖñ³¾°É«
gra.setColor(Color.yellow);
gra.fillRect(1,1,33,12);
//ÉèÖÃ×ÖÌåÉ«
gra.setColor(Color.black);
gra.setFont(mFont);
//Êä³öÊý×Ö
char c;
for(int i=0;i<4;i++) {
c=s.charAt(i);
gra.drawString(c+"",i*7+4,11); //7Ϊ¿í¶È£¬11ΪÉÏϸ߶ÈλÖÃ
}
JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
}
ÍƼöÐÅÏ¢
- ÔÝÎ޼Ǽ
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- java urlÖØд¼¼Êõ(UrlReWriter)
- [ת]JavaµÄÊý×飨Array£©¡¢Vector¡¢ArrayLis....
- jsp»·¾³ÏÂajaxÂÒÂëÎÊÌâµÄ½â¾ö
- JSP¼¼Êõ Ö¸Áî ÂÒÂëÎÊÌâ ÔËÐÐÔÀíºÍ¾Å´óÒþʽ¶ÔÏó web¿ª·¢µÄË....
- JAVA ˮӡ ͼƬ ÎÄ×Ö
- java¶þ½øÖÆ£¬ÔÂë¡¢·´Âë¡¢²¹Â롢λÔËËã
- Java WebÓ¦ÓÃÆô¶¯¼ä¸ôÖ´ÐеijÌÐò
- jspÉú³ÉxmlÎļþʾÀý
- javaÖÐÀà±äÁ¿¡¢Àà·½·¨¡¢ÊµÀý±äÁ¿¡¢ÊµÀý·½·¨
- JSPÒ³ÃæµÄÎåÖÖÌøת·½·¨
ÆÀÂÛ