版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、J2EE軟件開發(fā)課程實驗報告姓名 王 爍 學(xué)號 201308003104 專業(yè) 軟件工程 班級 1301 指導(dǎo)教師及職稱 程文志(助教) 開課學(xué)期 2015 至 2016 學(xué)年 下 學(xué)期上課時間 2016 年 4 月 28 日 湖南科技學(xué)院教務(wù)處編印實驗題目Servlet表單驗證碼的設(shè)計1 實驗?zāi)康模?) 熟悉Servlet的處理流程;2) 能夠在頁面中熟練的使用Servlet生成驗證碼;3) 熟悉Web開發(fā)的流程;4) 掌握頁面設(shè)計的各種技巧。2 軟硬件環(huán)境:軟件環(huán)境:MyEclipse、JDK環(huán)境硬件環(huán)境:電腦一臺3 實驗內(nèi)容簡述:a) 完成一個表單驗證碼的設(shè)計:在驗證生成之前,有一個選擇
2、界面,該界面有兩個選項;(form.jsp)(1) 4位或6位的選擇,對應(yīng)生成驗證碼為4位或6位;(2) 驗證碼內(nèi)容的選擇:內(nèi)容分為三種(數(shù)字、字母、數(shù)字+字母)b) 驗證碼的生成要求采用Servlet來生成,其它界面可以用jsp來響應(yīng);c) 登陸頁面:(login.jsp) (提示:JavaScript的代碼)(1) 用戶名、密碼存儲在web.xml文件(context-parm存儲);(2) 驗證碼點擊后會生成新的驗證;d) 驗證頁面:(1) 用戶名、密碼錯誤,就返回登陸頁面,并提示登陸錯誤的相關(guān)信息(用戶名和密碼錯誤);(2) 驗證碼錯誤,就提示驗證碼錯誤;(3) 用戶輸入的驗證碼不分大
3、小寫。e) 驗證成功:(1) 提示:登錄成功;(2) 登陸成功后,就顯示個人信息,要求采用兩列表格姓名張三-$name學(xué)號2013000b) 以列表的方式顯示所有的用戶信息,包含(用戶名、密碼、姓名、學(xué)號、專業(yè)、班級、學(xué)院);5) 數(shù)據(jù)處理(web.xml)將用戶名和密碼存儲在web.xml文件中。4實現(xiàn)過程#choosestyles.jsp dynamicVerificationCode.html 選擇驗證碼規(guī)格 驗證碼長度 1 100 驗證碼類型 !- - 字母 數(shù)字 #login.jsp base href= login.jsp function reload() document.ge
4、tElementById(identityImage).src=generateImg.action?ts= + new Date().getTime(); 請登錄 用戶名: 密碼: #validating.jsp base href= 登錄中. USERINPUT SYS INFO #home.jsp base href= HOME 歡迎回來,$userName. 注銷 姓名: $studentName 學(xué)號: $studentNumber #GetIdentityStylesServletpackage com.shawn.controller;import java.io.IOExcep
5、tion;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class GetIdentityStylesServlet extends HttpServlet public GetIdentityStylesServlet() super();p
6、ublic void destroy() super.destroy(); / Just puts destroy string in log/ Put your code herepublic void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException int length = Integer.valueOf(request.getParameter(length).intValue();String types = request.getP
7、arameterValues(type);request.getSession().setAttribute(length, length);request.getSession().setAttribute(types, types);response.sendRedirect(login.jsp);public void init() throws ServletException #DynamicVerificationCodeServletpackage com.shawn.controller;import com.shawn.model.VerificationCodeFactor
8、y;import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEGImageEncoder;import java.awt.Color;import java.awt.Font;import java.awt.Graphics2D;import java.awt.image.BufferedImage;import java.io.IOException;import java.util.Random;import javax.servlet.ServletException;import javax
9、.servlet.ServletOutputStream;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class DynamicVerificationCodeServlet extends HttpServlet private static final long serialVersionUID = 1L;/* * Constructor of the object
10、. */public DynamicVerificationCodeServlet() super();public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code herepublic void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException response.setContentType(image/jpeg);Integer
11、length = (Integer) request.getSession().getAttribute(length);String types = (String) request.getSession().getAttribute(types);System.out.println(length);System.out.println();for(String x : types)System.out.println(x);int type = 0;if(types.length = 3 | types0.equals(hidden)type = 0;elseif(types0.equa
12、ls(number)type = 1;elsetype = 2;String randomString = VerificationCodeFactory.getVerificationCode(length, type);request.getSession().setAttribute(randomString, randomString);int width = (int) (12.5 * length);int height = 30;Color color = VerificationCodeFactory.getRandomColor();Color reverse = Verif
13、icationCodeFactory.getReverseColor(color);System.out.println();BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);Graphics2D g = bi.createGraphics();g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 16);g.setColor(color);g.fillRect(0, 0, width, height);g.setColor(reverse);g
14、.drawString(randomString, 5, 20);Random random = new Random();for (int i = 0, n = random.nextInt(100); i n; i+) g.drawRect(random.nextInt(width), random.nextInt(height), 1, 1);ServletOutputStream out = response.getOutputStream();JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);encoder.enc
15、ode(bi);out.flush();/* * Initialization of the servlet. * * throws ServletException if an error occurs */public void init() throws ServletException / Put your code here#package com.shawn.controller;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.RequestDispatcher;import ja
16、vax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class LogoutServlet extends HttpServlet /* * Constructor of the object. */public LogoutServlet() super();/* * Destruction of the servle
17、t. */public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code here/* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException request.getSession().invalidate();response.sen
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度叉車租賃及安全防護(hù)設(shè)備供應(yīng)合同4篇
- 2025年版拍賣公司藝術(shù)品交易傭金分成合同4篇
- 2025年度個人房源信息發(fā)布與客戶關(guān)系維護(hù)合同3篇
- 二零二五年度金融衍生品出借咨詢與風(fēng)險管理合同3篇
- 2025年度門禁系統(tǒng)采購與施工安裝一體化服務(wù)合同4篇
- 2025年度木門行業(yè)環(huán)保檢測與認(rèn)證合同范本4篇
- 二零二五年度酒店式餐廳經(jīng)營管理權(quán)轉(zhuǎn)讓合同范本4篇
- 2025年度船舶新能源份額轉(zhuǎn)讓與技術(shù)研究合同2篇
- 二零二五版智能門禁系統(tǒng)項目監(jiān)理合同4篇
- 2025年度旅游公司導(dǎo)游個人聘用合同范本4篇
- 山東鐵投集團(tuán)招聘筆試沖刺題2025
- 真需求-打開商業(yè)世界的萬能鑰匙
- 2025年天津市政集團(tuán)公司招聘筆試參考題庫含答案解析
- GB/T 44953-2024雷電災(zāi)害調(diào)查技術(shù)規(guī)范
- 2024-2025學(xué)年度第一學(xué)期三年級語文寒假作業(yè)第三天
- 2024年列車員技能競賽理論考試題庫500題(含答案)
- 心律失常介入治療
- 6S精益實戰(zhàn)手冊
- 展會場館保潔管理服務(wù)方案
- 監(jiān)理從業(yè)水平培訓(xùn)課件
- 廣東省惠州市實驗中學(xué)2025屆物理高二第一學(xué)期期末綜合測試試題含解析
評論
0/150
提交評論