📄 rondom_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 rondom_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
//²úÉúËæ»úÑÕÉ«º¯ÊýgetRandColor
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);
}
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\n\r\n\r\n\r\n");
out.write("\r\n\r\n");
//ÉèÖÃÒ³Ãæ²»»º´æ
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
//´´½¨Ëæ»úÀà
Random r = new Random();
// ÔÚÄÚ´æÖд´½¨Í¼Ïñ£¬¿í¶ÈΪwidth£¬¸ß¶ÈΪheight
int width=60, 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));
// Ëæ»ú²úÉú200Ìõ¸ÉÈÅÖ±Ïߣ¬Ê¹Í¼ÏñÖеÄÈÏÖ¤Âë²»Ò×±»ÆäËû·ÖÎö³ÌÐò̽²âµ½
gc.setColor(getRandColor(160,200));
for (int i=0;i<200;i++){
int x1 = r.nextInt(width);
int y1 = r.nextInt(height);
int x2 = r.nextInt(15);
int y2 = r.nextInt(15);
gc.drawLine(x1,y1,x1+x2,y1+y2);
}
//Ëæ»ú²úÉú100¸ö¸ÉÈŵ㣬ʹͼÏñÖеÄÑéÖ¤Âë²»Ò×±»ÆäËû·ÖÎö³ÌÐò̽²âµ½
gc.setColor(getRandColor(120,240));
for (int i=0;i<100;i++)
{
int x = r.nextInt(width);
int y = r.nextInt(height);
gc.drawOval(x,y,0,0);
}
// Ëæ»ú²úÉú4λÊý×ÖµÄÑéÖ¤Âë
String RS="";
String rn="";
for(int i=0;i<4;i++){
//²úÉú10ÒÔÄÚËæ»úÊý×Örn
rn=String.valueOf(r.nextInt(10));
RS+=rn;
//½«ÈÏÖ¤ÂëÓÃdrawStringº¯ÊýÏÔʾµ½Í¼ÏñÀï
gc.setColor(new Color(20+r.nextInt(110),20+r.nextInt(110),20+r.nextInt(110)));
gc.drawString(rn,13*i+6,16);
}
// ÊÍ·ÅͼÐÎÉÏÏÂÎÄ»·¾³
gc.dispose();
// ½«ÈÏÖ¤ÂëRS´æÈëSESSIONÖй²Ïí
session.setAttribute("random",RS);
// Êä³öÉú³ÉºóµÄÑéÖ¤ÂëͼÏñµ½Ò³Ãæ
try{
ImageIO.write(pic, "JPEG", response.getOutputStream());
} catch (Exception e) {}
out.write("\r\n\r\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.handlePageException(t);
}
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -