資源簡介
基于ssh框架的java用戶注冊以及登錄驗證的源代碼!

代碼片段和文件信息
import?java.awt.Color;
import?java.awt.Font;
import?java.awt.Graphics;
import?java.awt.image.BufferedImage;
import?java.io.IOException;
import?java.util.Random;
import?javax.imageio.ImageIO;
import?javax.servlet.ServletException;
import?javax.servlet.http.HttpServlet;
import?javax.servlet.http.HttpServletRequest;
import?javax.servlet.http.HttpServletResponse;
import?javax.servlet.http.HttpSession;
public?class?AuthImg?extends?HttpServlet{
private?Font?mFont=new?Font(“Arial?Black“Font.PLAIN16);
public?void?init()throws?ServletException{
super.init();
}
public?Color?getRandColor(int?fcint?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(rgb);
}
public?void?Service(HttpServletRequest?requestHttpServletResponse?response)throws?ServletExceptionIOException{
response.setHeader(“Pragma““No-cache“);
response.setDateHeader(“Expires“0);
response.setContentType(“image/jpeg“);
int?width=100;
int?height=18;
BufferedImage?image=new?BufferedImage(widthheightBufferedImage.TYPE_INT_RGB);
Graphics?g=image.getGraphics();
Random?random=new?Random();
g.setColor(getRandColor(200250));
g.drawRect(00width-1height-1);
g.setFont(mFont);
g.setColor(getRandColor(160200));
for(int?i=0;i<155;i++){
int?x=random.nextInt(width-1);
int?y=random.nextInt(height-1);
int?x1=random.nextInt(6)+1;
int?y1=random.nextInt(12)+1;
g.drawLine(x?y?x+x1?y+y1);
}
for(int?i=0;i<70;i++){
int?x=random.nextInt(width-1);
int?y=random.nextInt(height-1);
int?x1=random.nextInt(12)+1;
int?y1=random.nextInt(6)+1;
g.drawLine(x?y?x-x1y-?y1);
}
String?sRand=““;
for(int?i=0;i<6;i++){
String?tmp=getRandomChar();
sRand+=tmp;
g.setColor(new?Color(20+random.nextInt(110)20+random.nextInt(110)20+random.nextInt(110)));
g.drawString(tmp15*i+1015);
HttpSession?session=request.getSession(true);
session.setAttribute(“rand“sRand);
g.dispose();
ImageIO.write(image?“JPEG“?response.getOutputStream());
}
}
private?String?getRandomChar(){
int?rand=(int)Math.round(Math.random()*2);
long?itmp=0;
char?ctmp=‘\u0000‘;
switch(rand){
case?1:
itmp=Math.round(Math.random()*25+65);
case?2:
itmp=Math.round(Math.random()*25+97);
}
ctmp=(char)itmp;
return?String.valueOf(ctmp);
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1425??2010-11-02?19:41??LoginAndRegister\.classpath
?????文件????????566??2010-10-23?18:12??LoginAndRegister\.myhibernatedata
?????文件????????321??2010-11-02?19:38??LoginAndRegister\.myme
?????文件????????240??2010-10-23?18:03??LoginAndRegister\.mystrutsdata
?????文件???????1915??2010-10-23?18:43??LoginAndRegister\.project
?????文件????????500??2010-10-23?17:57??LoginAndRegister\.settings\.jsdtscope
?????文件????????330??2010-10-23?17:57??LoginAndRegister\.settings\org.eclipse.jdt.core.prefs
?????文件?????????49??2010-10-23?17:57??LoginAndRegister\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件??????????6??2010-10-23?17:57??LoginAndRegister\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件????????462??2010-10-23?18:12??LoginAndRegister\.springBeans
?????文件???????2512??2010-10-30?10:12??LoginAndRegister\src\applicationContext.xm
?????文件???????2528??2010-10-24?16:08??LoginAndRegister\src\AuthImg.java
?????文件???????1186??2010-10-24?10:48??LoginAndRegister\src\ba
?????文件????????194??2010-10-23?22:55??LoginAndRegister\src\ba
?????文件???????1061??2010-10-24?10:54??LoginAndRegister\src\LoginAction.java
?????文件????????759??2010-11-01?12:09??LoginAndRegister\src\RegisterAction.java
?????文件????????792??2010-10-27?22:29??LoginAndRegister\src\struts.xm
?????文件????????476??2010-10-27?16:16??LoginAndRegister\src\User.hbm.xm
?????文件????????492??2010-10-27?16:15??LoginAndRegister\src\User.java
?????文件????????249??2010-10-23?22:55??LoginAndRegister\src\UserDao.java
?????文件???????1102??2010-10-23?22:55??LoginAndRegister\src\UserDaoHibernate.java
?????文件????????220??2010-10-23?22:55??LoginAndRegister\src\UserManager.java
?????文件???????1064??2010-10-31?22:11??LoginAndRegister\src\UserManagerImpl.java
?????文件????????748??2010-10-24?17:21??LoginAndRegister\src\ValidateNameAction.java
?????文件????????799??2010-10-26?19:08??LoginAndRegister\WebRoot\index.jsp
?????文件???????1185??2010-10-27?17:07??LoginAndRegister\WebRoot\login.jsp
?????文件?????????36??2010-10-23?17:57??LoginAndRegister\WebRoot\me
?????文件???????1422??2010-10-27?22:26??LoginAndRegister\WebRoot\register.jsp
?????文件???????2512??2010-10-30?10:12??LoginAndRegister\WebRoot\WEB-INF\classes\applicationContext.xm
?????文件???????3792??2010-11-02?19:41??LoginAndRegister\WebRoot\WEB-INF\classes\AuthImg.class
............此處省略26個文件信息
評論
共有 條評論