在线等答案关于jsp的(内附代码)
<%@ page contentType="image/jpeg" %><%@ page import="java.awt.*,java.awt.image.*"%>
<%@ page import="java.util.*,javax.imageio.*" %>
<%!
Color getRandColor(int fc,int bc){
Random r = new Random();
if(fc>255)
fc = 255;
if(bc>255)
bc = 255;
int red = fc+r.nextInt(bc-fc);
int green = fc+r.nextInt(bc-fc);
int blue = fc+r.nextInt(bc-fc);
return new Color(red,green,blue);
}
%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
int width=60;
int height=20;
BufferedImage pic = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics gc = pic.getGraphics();//就这里老报找不到源的异常!!!
gc.setColor(getRandColor(200,250));
gc.fillRect(0,0,width,height);
gc.setFont(new Font("Times New Roman",Font.PLAIN,18));
gc.setColor(new Color(0,0,0));
gc.drawRect(0,0,width-1,height-1);
gc.drawString("************",50,50);
gc.drawString("Hello,BMY!",50,100);
gc.dispose();
ImageIO.write(pic,"JPEG",response.getOutputStream());
%>