【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了image_jsp.java相关资料,希望对各位网友有所帮助!
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.imageio.*;
public final class image_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
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);
}
private static java.util.Vector _jspx_dependants;
public java.util.List getDependants() {
return _jspx_dependants;
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;
try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("image/jpeg");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write('\r');
out.write('\n');
out.write('\r');
out.write('\n');
//脡猫脰脙脪鲁脙忙虏禄禄潞麓忙
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();
// 脢盲鲁枚脥录脧贸碌陆脪鲁脙忙
ImageIO.write(image, "JPEG", response.getOutputStream());
out.write('\r');
out.write('\n');
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (_jspx_page_context != null) _jspx_page_context.handle