📄 code.jsp
字号:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@page import="java.awt.*,java.awt.image.*,java.util.*,com.sun.image.codec.jpeg.*"%>
<%!Color getColor(int a,int b)
{
int n=b-a;
Random rd=new Random();
int cr=a+rd.nextInt(n);
int cg=a+rd.nextInt(n);
int cb=a+rd.nextInt(n);
return new Color(cr,cg,cb);
}%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Explires",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(getColor(200,250));
g.fillRect(0,0,width,height);
g.setFont(new Font("Times New Roman",Font.BOLD,18));
g.setColor(getColor(160,200));
for(int i=0;i<160;i++)
{
int x=random.nextInt(width);
int y=random.nextInt(height);
int x1=random.nextInt(12);
int y1=random.nextInt(12);
g.drawLine(x,y,x+x1,y+y1);
}
String number=String.valueOf(1000+random.nextInt(8999));
String name=request.getParameter("codename");
session.setAttribute(name,number);
g.setColor(getColor(20,130));
int x=(int)(width*0.2);
int y=(int)(height*0.8);
g.drawString(number,x,y);
g.dispose();
JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(response.getOutputStream());
encoder.encode(image);
out.close();
%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<br>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -