資源簡介
基于ssh的整合框架,實(shí)行了增刪改查,登錄和修改等功能,適合新手學(xué)習(xí)和使用。
代碼片段和文件信息
package?com.sqt.action.user;
import?java.awt.Color;
import?java.awt.Font;
import?java.awt.Graphics;
import?java.awt.image.BufferedImage;
import?java.io.ByteArrayInputStream;
import?java.io.ByteArrayOutputStream;
import?java.util.Map;
import?java.util.Random;
import?javax.imageio.ImageIO;
import?javax.servlet.http.HttpServletResponse;
import?org.apache.struts2.ServletActionContext;
import?com.opensymphony.xwork2.ActionContext;
import?com.opensymphony.xwork2.ActionSupport;
public?class?CreateImageAction?extends?ActionSupport?{
private?ByteArrayInputStream?inputStream;
????private?static?int?WIDTH?=?60;
????private?static?int?HEIGHT?=?20;
????public?ByteArrayInputStream?getInputStream()
????{
????????return?inputStream;
????}
????public?void?setInputStream(ByteArrayInputStream?inputStream)
????{
????????this.inputStream?=?inputStream;
????}
????private?static?String?createRandom()
????{
????????String?str?=?“0123456789qwertyuiopasdfghjklzxcvbnm“;
????????char[]?rands?=?new?char[4];
????????Random?random?=?new?Random();
????????for?(int?i?=?0;?i?4;?i++)
????????{
????????????rands[i]?=?str.charAt(random.nextInt(36));
????????}
????????return?new?String(rands);
????}
????private?void?drawBackground(Graphics?g)
????{
????????//?畫背景
????????g.setColor(new?Color(0xDCDCDC));
????????g.fillRect(0?0?WIDTH?HEIGHT);
????????//?隨機(jī)產(chǎn)生?120?個(gè)干擾點(diǎn)
????????for?(int?i?=?0;?i?120;?i++)
????????{
????????????int?x?=?(int)?(Math.random()?*?WIDTH);
????????????int?y?=?(int)?(Math.random()?*?HEIGHT);
????????????int?red?=?(int)?(Math.random()?*?255);
????????????int?green?=?(int)?(Math.random()?*?255);
????????????int?blue?=?(int)?(Math.random()?*?255);
????????????g.setColor(new?Color(red?green?blue));
????????????g.drawOval(x?y?1?0);
????????}
????}
????private?void?drawRands(Graphics?g?String?rands)
????{
????????g.setColor(Color.BLACK);
????????g.setFont(new?Font(null?Font.ITALIC?|?Font.BOLD?18));
????????//?在不同的高度上輸出驗(yàn)證碼的每個(gè)字符
????????g.drawString(““?+?rands.charAt(0)?1?17);
????????g.drawString(““?+?rands.charAt(1)?16?15);
????????g.drawString(““?+?rands.charAt(2)?31?18);
????????g.drawString(““?+?rands.charAt(3)?46?16);
????????System.out.println(rands);
????}
????@Override
????public?String?execute()?throws?Exception
????{
???? System.out.println(“----獲取驗(yàn)證碼----“);
????????HttpServletResponse?response?=?ServletActionContext.getResponse();
???????
????????//?設(shè)置瀏覽器不要緩存此圖片
????????response.setContentType(“image/jpeg“);
????????response.setHeader(“Pragma“?“No-cache“);
????????response.setHeader(“Cache-Control“?“no-cache“);
????????response.setDateHeader(“Expires“?0);
????????
????????String?rands?=?createRandom();
????????BufferedImage?image?=?new?BufferedImage(WIDTH?HEIGHT
????????????????BufferedImage.TYPE_INT_RGB);
????????Graphics?g?=?image.getGraphics();
????????//?產(chǎn)生圖像
????????drawBackground(g);
????????drawRands(g?rand
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-09-12?09:25??ssh2_AddPage\
?????文件?????????648??2015-09-12?09:31??ssh2_AddPage\.classpath
?????目錄???????????0??2015-09-12?09:25??ssh2_AddPage\.git\
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\branches\
?????文件??????????23??2015-08-24?09:26??ssh2_AddPage\.git\COMMIT_EDITMSG
?????文件??????????79??2015-08-24?09:25??ssh2_AddPage\.git\config
?????文件??????????23??2015-08-24?09:25??ssh2_AddPage\.git\HEAD
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\hooks\
?????文件????????9352??2015-08-24?09:26??ssh2_AddPage\.git\index
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\logs\
?????文件?????????167??2015-08-24?09:26??ssh2_AddPage\.git\logs\HEAD
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\logs\refs\
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\logs\refs\heads\
?????文件?????????167??2015-08-24?09:26??ssh2_AddPage\.git\logs\refs\heads\master
?????目錄???????????0??2015-09-12?09:25??ssh2_AddPage\.git\ob
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件?????????657??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件??????????21??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件?????????362??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件?????????116??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件?????????254??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件??????????46??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件??????????65??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????目錄???????????0??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件???????51331??2015-09-12?09:24??ssh2_AddPage\.git\ob
?????文件?????????488??2015-09-12?09:24??ssh2_AddPage\.git\ob
............此處省略335個(gè)文件信息
評(píng)論
共有 條評(píng)論