|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
首先第一点:jsp,servlet,javabean这些最基本的,嘿嘿,就算你是高手的话,在大行的企业级应用的话还是需要框架的,一个好的框架确实能构解决许多问题。js|考证码random.jsp文件代码:
<%@pageautoFlush="false"import="java.awt.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.util.*"%>
<%@pageimport="org.apache.commons.lang.RandomStringUtils"%>
<%
RandomStringUtilsrs=newRandomStringUtils();
Stringrandom=rs.randomAlphanumeric(4);
session.setAttribute("random",random);
%>
<%
out.clear();
response.setContentType("image/jpeg");
response.addHeader("pragma","NO-cache");
response.addHeader("Cache-Control","no-cache");
response.addDateHeader("Expries",0);
intwidth=100,height=40;
BufferedImageimage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphicsg=image.getGraphics();
//以下添补背景?色
g.setColor(Color.GRAY);
FontDeFont=newFont("SansSerif",Font.PLAIN,32);
g.setFont(DeFont);
g.fillRect(0,0,width,height);
//?置字体?色
g.setColor(Color.RED);
g.drawString(random,3,30);
g.dispose();
ServletOutputStreamoutStream=response.getOutputStream();
JPEGImageEncoderencoder=JPEGCodec.createJPEGEncoder(outStream);
encoder.encode(image);
outStream.close();
%>
test.jsp文件代码以下:
<%@pagecontentType="text/html;charset=UTF-8"language="java"import="java.sql.*"errorPage=""%>
<html>
<head>
<title>UntitledDocument</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>
<body>
<imgsrc="random.jsp">
</body>
</html>
假如不想导进Apache的包能够本人编译上面这个文件
//FrontEndPlusGUIforJAD
//DeCompiled:RandomStringUtils.class
packageorg.apache.commons.lang;
importjava.util.Random;
publicclassRandomStringUtils
{
privatestaticfinalRandomRANDOM=newRandom();
publicRandomStringUtils()
{
}
publicstaticStringrandom(intcount)
{
returnrandom(count,false,false);
}
publicstaticStringrandomAscii(intcount)
{
returnrandom(count,32,127,false,false);
}
publicstaticStringrandomAlphabetic(intcount)
{
returnrandom(count,true,false);
}
publicstaticStringrandomAlphanumeric(intcount)
{
returnrandom(count,true,true);
}
publicstaticStringrandomNumeric(intcount)
{
returnrandom(count,false,true);
}
publicstaticStringrandom(intcount,booleanletters,booleannumbers)
{
returnrandom(count,0,0,letters,numbers);
}
publicstaticStringrandom(intcount,intstart,intend,booleanletters,booleannumbers)
{
returnrandom(count,start,end,letters,numbers,null);
}
publicstaticStringrandom(intcount,intstart,intend,booleanletters,booleannumbers,charset[])
{
if(start==0&&end==0)
{
end=122;
start=32;
if(!letters&&!numbers)
{
start=0;
end=0x7fffffff;
}
}
StringBufferbuffer=newStringBuffer();
intgap=end-start;
while(count--!=0)
{
charch;
if(set==null)
ch=(char)(RANDOM.nextInt(gap)+start);
else
ch=set[RANDOM.nextInt(gap)+start];
if(letters&&numbers&&Character.isLetterOrDigit(ch)||letters&&Character.isLetter(ch)||numbers&&Character.isDigit(ch)||!letters&&!numbers)
buffer.append(ch);
else
count++;
}
returnbuffer.toString();
}
publicstaticStringrandom(intcount,Stringset)
{
returnrandom(count,set.toCharArray());
}
publicstaticStringrandom(intcount,charset[])
{
returnrandom(count,0,set.length-1,false,false,set);
}
}
java比较简单,没有C++的烦琐,但学习时最好有C++为基础.与JSP和SQL起应用,功能强大. |
|