Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JSP Éú³ÉËæ»úÑéÖ¤ÂëͼƬ


<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%!
Color getRandColor(int fc,int bc){//¸ø¶¨·¶Î§»ñµÃËæ»úÑÕÉ«
Random random = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
%>
<%
//ÉèÖÃÒ³Ãæ²»»º´æ
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
// ÔÚÄÚ´æÖд´½¨Í¼Ïó
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// »ñȡͼÐÎÉÏÏÂÎÄ
Graphics g = image.getGraphics();
//Éú³ÉËæ»úÀà
Random random = new Random();
// É趨±³¾°É«
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);
//É趨×ÖÌå
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
//»­±ß¿ò
//g.setColor(new Color());
//g.drawRect(0,0,width-1,height-1);
// Ëæ»ú²úÉú155Ìõ¸ÉÈÅÏߣ¬Ê¹Í¼ÏóÖеÄÈÏÖ¤Âë²»Ò×±»ÆäËü³ÌÐò̽²âµ½
g.setColor(getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}
// È¡Ëæ»ú²úÉúµÄÈÏÖ¤Âë(4λÊý×Ö)
String sRand=""
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
// ½«ÈÏÖ¤ÂëÏÔʾµ½Í¼ÏóÖÐ
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));//µ÷Óú¯Êý³öÀ´µÄÑÕÉ«Ïàͬ£¬¿ÉÄÜÊÇÒòΪÖÖ×ÓÌ«½Ó½ü£¬ËùÒÔÖ»ÄÜÖ±½ÓÉú³É
g.drawString(rand,13*i+6,16);
}
// ½«ÈÏÖ¤Âë´æÈëSESSION
session.setAttribute("rand",sRand);
// ͼÏóÉúЧ
g.dispose();
out.clear();
request.setAttribute("gzip", "false");
// Êä³öͼÏóµ½Ò³Ãæ
ImageIO.write(image, "JPEG", response.getOutputStream());
return;
%>


Ïà¹ØÎĵµ£º

jsp servlet ÖÐsetAttribute()ºÍgetParameter()Çø±ð

setAttribute()ÊÇÓÃÓÚ·þÎñÆ÷¶ËÉèÖÃÊôÐÔÏò¿Í»§¶Ë·¢Ë͸ÃÊôÐÔ£¬ÔÚ¿Í»§¶Ëͨ¹ýgetAttribute£¨£©»ñµÃÊôÐÔ¡£setAttribute()Ò²ÄÜ´«µÝ¶ÔÏó¡£
setParameter()Êǿͻ§¶ËÏò·þÎñÆ÷¶Ë·¢ËÍÊôÐÔ£¬Ö»ÄÜ´«×Ö·û£¬ÓÃÓÚget/postµÄÊýÖµ´«µÝ£¬ÔÚ·þÎñ¶ËÓÃgetParameter£¨£©»ñÈ¡£¬Ò³ÃæÖÐÓÐforward´Ó¶¨ÏòÒ³ÃæµÄµØÖ·ÖеIJÎÊýÒ²ÄÜÓÃgetParameter£¨£©»ñÈ¡¡ ......

ÀûÓÃjspÉÏ´«excel

Ò»¡¢ÉÏ´«
ÒýÈë°ü£ºorg.apache.commons.fileupload.*
jsp´úÂ룺 DiskFileUpload fu = new DiskFileUpload();
      List list = fu.parseRequest(request);
      if(list != null){
       System.out.println(list.size());
  ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ