




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、java_javaWeb注冊,登陸,注銷功能的實現(xiàn):注冊頁:regist.jsp:pageEncoding=UTF-8%Insert title herefunction changeImg()document.getElementById(myImg).src=$pageContext.request.contextPath/servlet/CheckCodeServlet? +new Date().getTime();function validataForm()var username = document.getElementById(username).value;if(userna
2、me = )alert(戶名不能為空!);return false;var password = document.getElementById(password).value;if(password = )alert(密碼不能為空!);return false;var repassword = document.getElementById(repassword).value;if(password != repassword)alert(兩次密碼不致!);return false;var email = document.getElementById(email).value;if(ema
3、il.match(s*w+(?:.0,1w-+)*a-zA-Z0-9+(?:-.a-zA-Z0-9+)*.a-zA-Z+s*$)=null)alert(哥們,郵箱地址法);return false;確認密碼:郵箱:nclick=changeImg(); style=cursor: pointer; id=myImg:.驗證碼servlet:CheckCodeServlet.java完成頁顯驗證碼的效果:package com.itcode.view;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;impor
4、t java.awt.Graphics2D;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.HttpServletResp
5、onse;public class CheckCodeServlet extends HttpServlet / ctrl + shift +X 變寫 Yprivate final int WIDTH = 120;private final int HEIGHT = 30;public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException response.setHeader(cache-control, no-cache);respons
6、e.setHeader(pragma, no-cache);response.setDateHeader(expires, -1);/ 1.在內存中構建出張 圖BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);Graphics2D graphics = (Graphics2D) image.getGraphics();/ 將 背景設置 為 .graphics.setColor(Color.WHITE);graphics.fillRect(0, 0,WIDTH,HEIGHT);/
7、狀態(tài)機/ 畫 矩形 . 之前 由于已經設置 過 顏 ,就相當于 維護了 個狀態(tài)機,所以 你需要 再次調 setCorlor , 否則 就看不到 你 畫 的矩形了 .graphics.setColor(Color.BLUE);graphics.drawRect(0, 0,WIDTH-1, HEIGHT-1);/ 準備好 要 使的 漢字./String base =ABCDEFGHIJKLMNOPQRST;String base =u7684u4e00u4e86u662fu6211u4e0du5728u4ebau4eecu6709u6765u4ed6u8fd9u4e0au7740u4e2au573
8、0uRandom rand = new Random();/ 設置顏graphics.setColor(Color.RED);/ 設置 字體graphics.setFont(new Font(宋體,Font.BOLD,18);StringBuilder sb = new StringBuilder();int m =10;/ 在for循環(huán)中 將 漢字畫上去for (int i = 0;i 4;i+) int index = rand.nextInt(base.length();char charAt = base.charAt(index);/ -30 - 30int jiaodu = ran
9、d.nextInt(60) -30;double theta = jiaodu*Math.PI/180;graphics.rotate(theta, m,15);graphics.drawString(charAt +, m,20);sb.append(charAt);graphics.rotate(-theta, m,15);m+=25;/ 畫 4 條線graphics.setColor(Color.GREEN);for (int i = 0;i Insert title here$message 戶名:密碼:記住戶名與密碼六:LoginServlet,查看戶登陸時所填寫的信息是否與數(shù)據庫件
10、中的相應數(shù)據符合,若符合,則顯登陸成功,若不符合,則請求轉發(fā)到登陸頁:package com.itcode.controller;import java.io.IOException;import java.lang.reflect.InvocationTargetException;import javax.servlet.ServletException;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;imp
11、ort javax.servlet.http.HttpServletResponse;import mons.beanutils.BeanUtils;import com.itcode.model.User;import com.itcode.model.UserOperator;public class LoginServlet extends HttpServlet public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException U
12、ser user = new User();try BeanUtils.populate(user, request.getParameterMap(); catch (IllegalAccessException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (InvocationTargetException e) / TODO Auto-generated catch blocke.printStackTrace();UserOperator userOperator = new UserOperator()
13、;User existUser = userOperator.login(user);if(existUser = null)response.getWriter().println(戶名或密碼不正確,請重新輸!);request.getRequestDispatcher(/login.jsp).forward(request, response);else/登陸成功后,跳轉到頁。在 頁要判斷戶是否已經登陸request.getSession().setAttribute(existUser,existUser);if(on.equals(request.getParameter(rememb
14、er)/1.將戶名寫進cookie/Cookie usernameCookie = new Cookie(username,request.getParameter(username);Cookie usernameCookie = new Cookie(username,existUser.getUsername();usernameCookie.setMaxAge(60*12);usernameCookie.setPath(/);response.addCookie(usernameCookie);System.out.println(22);/2.將密碼寫進cookie/Cookie p
15、asswordCookie = new Cookie(password,request.getParameter(password);Cookie passwordCookie = new Cookie(password,existUser.getPassword();passwordCookie.setMaxAge(60*12);passwordCookie.setPath(/);response.addCookie(passwordCookie);System.out.println(44);response.sendRedirect(/user/index.jsp);public voi
16、d doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException doGet(request, response);七:注銷成功的實現(xiàn):在登錄成功后的頁寫個注銷的超鏈接,鏈接到注銷Servlet,LogoutServlet.javapackage com.itcode.controller;import java.io.IOException;import javax.servlet.ServletException;import javax.servle
17、t.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class LogoutServlet extends HttpServlet public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException /request.getSession().removeAttribute(existUser);request.getSession().invalidate();response.getWriter().println(fuck you have logou
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 個人出售房產合同范本
- 加裝空調工程合同范本
- 購房合同有購房合同范本
- 單位合伙建房合同范例
- 關于獨家合同范本
- 醫(yī)藥會議合同范本
- 單位給買車合同范本
- 化工項目整體承建合同范本
- 產品總經銷合同范本
- 醫(yī)院加盟合同范本
- 【《張裕酒業(yè)公司盈利能力探究》論文】
- 醫(yī)療器械臨床試驗質量管理規(guī)范培訓
- 寒假社會實踐大學生返鄉(xiāng)
- 站樁的知識講座
- 杭州園區(qū)招商規(guī)劃方案
- 【物業(yè)】《維修資金管理與使用》培訓課件
- HGT4134-2022 工業(yè)聚乙二醇PEG
- 鋁合金時效爐安全操作規(guī)程模版
- DB2201T 59-2023 冬季供暖運行參數(shù)氣象指標及分級
- 四川家庭農場補貼標準2023年
- 智能人體秤市場需求分析報告
評論
0/150
提交評論