




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、由于struts2標(biāo)簽的性能不好,項(xiàng)目組決定不使用,但是如果用struts2自帶的攔截器防止重復(fù)提交又必須struts標(biāo)簽,所以只好自定攔器實(shí)現(xiàn),具體步驟如下:新建攔截器類:public class TokenAtionInterceptor extends AbstractInterceptor public String intercept(ActionInvocation invocation) throws Exception Map session = invocation.getInvocationContext().getSession();HttpServletRequest
2、request = ServletActionContext.getRequest();String strGUID = RandomGUIDUtil.newGuid();/生成令牌String strRequestToken = (String)session.get(request_token);/取出會(huì)話中的令牌String strToken = request.getParameter(token);/頁(yè)面中的令牌if(strRequestToken != null & !strRequestToken.equals(strToken)/重復(fù)提交,重置令牌session.put(req
3、uest_token, strGUID);request.setAttribute(token, strGUID);return invalidToken;session.put(request_token, strGUID);request.setAttribute(token, strGUID);return invocation.invoke();/否則正常運(yùn)行建一個(gè)生成令牌的工具類:public class RandomGUIDUtil extends Object /* 日志管理類對(duì)象 */ private Logger logger = Logger.getLogger(this.
4、getClass().getName(); public String valueBeforeMD5 = ; public String valueAfterMD5 = ; private static Random myRand; private static SecureRandom mySecureRand; private static String s_id; /* * 靜態(tài)塊初始化 */ static mySecureRand = new SecureRandom(); long secureInitializer = mySecureRand.nextLong(); myRand
5、 = new Random(secureInitializer); try s_id = InetAddress.getLocalHost().toString(); catch (UnknownHostException e) System.out.println(構(gòu)造帶指定詳細(xì)消息和嵌入異常!); public RandomGUIDUtil() throws Exception getRandomGUID(false); public RandomGUIDUtil(boolean secure) throws Exception getRandomGUID(secure); /* * 隨機(jī)
6、生成GUID */ private void getRandomGUID(boolean secure) throws Exception MessageDigest md5 = null; StringBuffer sbValueBeforeMD5 = new StringBuffer(); try md5 = MessageDigest.getInstance(MD5); catch (NoSuchAlgorithmException e) logger.error(初始化MD5出錯(cuò)!); throw new NoSuchAlgorithmException(初始化MD5出錯(cuò)!); try
7、 long time = System.currentTimeMillis(); long rand = 0; if (secure) rand = mySecureRand.nextLong(); else rand = myRand.nextLong(); sbValueBeforeMD5.append(s_id); sbValueBeforeMD5.append(:); sbValueBeforeMD5.append(Long.toString(time); sbValueBeforeMD5.append(:); sbValueBeforeMD5.append(Long.toString
8、(rand); valueBeforeMD5 = sbValueBeforeMD5.toString(); md5.update(valueBeforeMD5.getBytes(); byte array = md5.digest(); StringBuffer sb = new StringBuffer(); for (int j = 0; j array.length; +j) int b = arrayj & 0xFF; if (b 0x10) sb.append(0); sb.append(Integer.toHexString(b); valueAfterMD5 = sb.toStr
9、ing(); catch (Exception e) logger.error(獲得MD5加密碼出錯(cuò)!); throw new Exception(初始化MD5出錯(cuò)!); /* * 生成一個(gè)GUID串 * return GUID * throws Exception */ public static String newGuid() throws Exception RandomGUIDUtil rdmGUID = new RandomGUIDUtil(); return rdmGUID.toString(); /* * 生成以主機(jī)串號(hào)、顯卡串號(hào)、主板號(hào),以保證唯一性的32位編碼 */ pub
10、lic String toString() String raw = valueAfterMD5.toUpperCase(); StringBuffer sb = new StringBuffer(); sb.append(raw.substring(0, 8); sb.append(raw.substring(8, 12); sb.append(raw.substring(12, 16); sb.append(raw.substring(16, 20); sb.append(raw.substring(20); return sb.toString(); 在struts配置文件中對(duì)應(yīng)的包下定義攔截器,注意順序,package里元素必須按照一定的順序排列。這個(gè)順序 就是 result-types interceptors default-interceptor-ref default-action-ref default-class
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 用紡織品企業(yè)縣域市場(chǎng)拓展與下沉戰(zhàn)略研究報(bào)告
- 2025年中國(guó)骨玉瓷制品市場(chǎng)調(diào)查研究報(bào)告
- 女士皮鞋企業(yè)數(shù)字化轉(zhuǎn)型與智慧升級(jí)戰(zhàn)略研究報(bào)告
- 仿制藥專利布局企業(yè)制定與實(shí)施新質(zhì)生產(chǎn)力戰(zhàn)略研究報(bào)告
- 仿制抗喉炎藥行業(yè)跨境出海戰(zhàn)略研究報(bào)告
- 辦公椅配件企業(yè)ESG實(shí)踐與創(chuàng)新戰(zhàn)略研究報(bào)告
- 婚慶策劃居間協(xié)議范本
- 物業(yè)管理人員個(gè)人工作計(jì)劃
- 公司生產(chǎn)經(jīng)營(yíng)工作總結(jié)
- 醫(yī)院醫(yī)生個(gè)人工作計(jì)劃
- 09J202-1 坡屋面建筑構(gòu)造(一)-2
- 光伏電站土建工程施工技術(shù)方案
- 2024年上海英語高考卷及答案完整版
- 物業(yè)公司客戶服務(wù)課件
- 腦卒中患者的康復(fù)護(hù)理查房
- 酶工程技術(shù)在茶葉深加工中的應(yīng)用
- 人教版英語八年級(jí)下冊(cè)全冊(cè)教案教學(xué)設(shè)計(jì)及教學(xué)反思
- 02J401 鋼梯【含03年修改】圖集
- 烹飪概論教學(xué)大綱
- Android移動(dòng)應(yīng)用開發(fā)基礎(chǔ)教程-教案
- 腦梗合并心衰護(hù)理查房
評(píng)論
0/150
提交評(píng)論