小白承包了一塊20畝的土地,依山傍水,風水不錯。聽朋友說去年玉米大賣,他也想嘗嘗甜頭,也就種上了玉米。
看著玉米茁壯成長,別提小小白心里多開心,心里盤算著玉米大買后,吃香喝辣的富貴生活。
好景不長,小小白這幾天發現玉米長得慢了,還出現了黃葉,黃頁面積還有擴大的趨勢。著急的小小白找到大隊的農業專家老周周,老周周說:“有病得治,玉米在生長期有著不同的階段,不同階段得有不同的護理措施,除了日常的除草、施肥,還得請專業的服務團隊,定期給莊稼體檢體檢啊,發現問題,才能更好的解決問題,我知道城里有一家專門做這個業務的公司,用了都說好”,說完遞給小小白一張名片。
小小白撥通了名片上的電話,接聽電話的是這個安全服務團隊的高級咨詢師陳老師,一聽小小白介紹種植的過程和出現的問題,就知道小小白是剛入門不久的小白,就開始給小小白耐心的講解莊稼體檢(網站滲透測試)的標準、基礎知識。
滲透測試是一種通過模擬攻擊者的攻擊技術、方法,繞過系統安全措施,最終取得系統控制權的安全測試方式。
剛入安全門不久的小白同學,如果能在開始就養成規范的操作習慣,后續提升安全修為是百利而無一害的。
近些年,安全圈內的“?!笔弦蛔?,結合多年豐富的牛逼經驗,重新定義了滲透測試過程,即“滲透測試執行標準(PTES:Penetration Testing ExcutionStandard)”。
Sinesafe把滲透測試過程劃分成7個階段:
1、 前期交互階段;
2、 情報收集階段;
3、 威脅建模階段;
4、 漏洞分析階段;
5、 滲透攻擊階段;
6、 后滲透攻擊階段;
7、 報告階段。
小小白聽得津津有味,還在筆記本上做著筆記。
每個階段,有著明確的目標。
1、前期交互階段。正式入場測試之前,我們甲方(小小白這樣的客戶)給乙方(“滲透測試”服務團隊)簽訂服務合同,明確測試范圍和目標,并由甲方給出書面的授權文件(沒有正式授權書的測試,都是違法的哦),雙方各執一份。
【Key Words】服務合同、測試范圍、測試目標、書面授權書
2、情報收集階段。采用各種可能的方法,搜集與將要攻擊的目標相關信息。搜集信息的方法主要分為外圍收集和試探收集。外圍信息收集方式包括社交媒體網絡、搜索引擎技術等;試探性收集包括端口掃描、漏洞掃描等。
【Key Words】帳號、口令、IP、端口、漏洞、資產版本信息
3、威脅建模階段。收集充分的情報之后,滲透團隊聚在一起,針對收集到的信息,頭腦風暴威脅建模和攻擊規劃,確定出最可行的攻擊通道。
【Key Words】攻擊規劃、頭腦風暴、開腦洞、戰略規劃
4、漏洞分析階段。我們的目標是:“找到蛀牙”。漏洞分析是在戰略確定后,從戰術面確定如何取得目標系統的訪問控制權。找出具體可利用漏洞,搜索或自行編寫滲透代碼,找出可以實施的滲透攻擊點,搭建模擬環境加以驗證。
【Key Words】漏洞分析、滲透攻擊代碼(POC)
5、滲透攻擊階段。將前面階段確定攻擊方式、方法,真正的應用在目標系統上,實施滲透測試,獲取控制權限。滲透測試過程中,可能會觸發目系統的防護措施,前期應有對應的逃逸機制,避免目標組織安全響應人員的警覺。
【Key Words】滲透測試、訪問控制權限、繞過權限
6、后滲透攻擊階段。拿到客戶一些系統的管理權限后,由此為“跳板”,實現內網“漫游”。在這個過程中,有經驗的大牛,能在信息有限的情況下,識別出關鍵信息基礎設施,找到客戶組織最有價值的信息和資產,并展示出對重要業務影響的攻擊路徑。
【Key Words】后滲透、關鍵信息基礎設施、內網滲透
7、報告階段。整理并輸出“體檢報告”,主要包括關鍵情報信息、漏洞、攻擊過程,以及造成業務影響后果的攻擊途徑,并梳理出防御體系中薄弱環節、短板,給出整改建議。
【Key Words】報告、脆弱點、威脅、風險
滲透測試相關術語
1.1 一些前置知識(包含但不限于) 腳本(asp、php、jsp) html(css、js、html) HTTP協議 CMS(B/S)
1.2 肉雞 被黑客入侵并被長期駐扎的計算機或服務器??梢噪S意控制,可以是任意系統的設備,對象可以是企業,個人,政府等等所有單位。
1.3 抓雞 利用使用量大的程序的漏洞,使用自動化方式獲取肉雞的行為。
1.4 Webshell 通過Web入侵的一種腳本工具,可以據此對網站服務進行一定程度的控制。
1.5 漏洞 硬件、軟件、協議等等的可利用安全缺陷,可能被攻擊者利用,對數據進行篡改,控制等。
1.6 木馬 通過向服務端提交一句簡短的代碼,配合本地客戶端實現webshell功能的木馬。 <%eval request("pass")%> <%execute(request("pass"))%> request("pass")接收客戶端提交的數據,pass為執行命令的參數值。 eval/execute 函數執行客戶端命令的內容
1.7 提權 操作系統低權限的賬戶將自己提升為管理員權限使用的方法。
1.8 后門 黑客為了對主機進行長期的控制,在機器上種植的一段程序或留下的一個"入口"。
1.9 跳板 使用肉雞IP來實施攻擊其他目標,以便更好的隱藏自己的身份信息。
1.10 旁站入侵 即同服務器下的網站入侵,入侵之后可以通過提權跨目錄等手段拿到目標網站的權限。常見的旁站查詢工具有:WebRobot、御劍、明小子和web在線查詢等
1.11 C段入侵 即同C段下服務器入侵。如目標ip為192.168.180.253 入侵192.168.180.*的任意一臺機器,然后利用一些黑客工具嗅探獲取在網絡上傳輸的各種信息。常用的工具有:在windows下有Cain,在UNIX環境下有Sniffit, Snoop, Tcpdump, Dsniff 等。
1.12 黑盒測試 在未授權的情況下,模擬黑客的攻擊方法和思維方式,來評估計算機網絡系統可能存在的安全風險。 黑盒測試不同于黑客入侵,并不等于黑站。黑盒測試考驗的是綜合的能力(OS、Datebase、、code、思路、社工)。思路與經驗積累往往決定成敗。
1.13 白盒測試 相對黑盒測試,白盒測試基本是從內部發起。白盒測試與黑盒測試恰恰相反,測試者可以通過正常渠道向被測單位取得各種資料,包括網絡拓撲、員工資料甚至網站或其它程序的代碼片斷,也能夠與單位的其它員工(銷售、程序員、管理者……)進行面對面的溝通。
1.14 黑白盒的另一種說法 知道源代碼和不知道源代碼的滲透測試。這時,黑盒測試還是傳統的滲透測試,而白盒測試就偏向于代碼審計。
1.15 APT攻擊 Advanced Persistent Threat,高級可持續性攻擊,是指組織(特別是政府)或者小團體利用先進的攻擊手段對特定目標進行長期持續性網絡攻擊的攻擊形式。 1.極強的隱蔽性 2.潛伏期長,持續性強 3.目標性強
小小白聽完安老師介紹后,發現自己缺少的是系統化的種植知識、風險控制意識,決定第二天就去城里找陳老師,談談服務細節,盡快把團隊請過來給莊稼把脈治病,減少不必要的損失。
本程序
腳本程序可以包含任意量的Java語句、變量、方法或表達式,只要它們在腳本語言中是有效的。
腳本程序的語法格式:
<% 代碼片段 %>
或者,您也可以編寫與其等價的XML語句,就像下面這樣:
<jsp:scriptlet> 代碼片段</jsp:scriptlet>
任何文本、HTML標簽、JSP元素必須寫在腳本程序的外面。
下面給出一個示例,同時也是本教程的第一個JSP示例:
<html><head><title>Hello World</title></head><body>Hello World!<br/><%out.println("Your IP address is " + request.getRemoteAddr());%></body></html>
注意:請確保Apache Tomcat已經安裝在C:\apache-tomcat-7.0.2目錄下并且運行環境已經正確設置。
將以上代碼保存在hello.jsp中,然后將它放置在 C:\apache-tomcat-7.0.2\webapps\ROOT目錄下,打開瀏覽器并在地址欄中輸入http://localhost:8080/hello.jsp。運行后得到以下結果:
中文編碼問題
如果我們要在頁面正常顯示中文,我們需要在 JSP 文件頭部添加以下代碼:<>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
接下來我們將以上程序修改為:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鳥教程(runoob.com)</title></head><body>Hello World!<br/><%out.println("你的 IP 地址 " + request.getRemoteAddr());%></body></html>
這樣中文就可以正常顯示了。
JSP聲明
一個聲明語句可以聲明一個或多個變量、方法,供后面的Java代碼使用。在JSP文件中,您必須先聲明這些變量和方法然后才能使用它們。
JSP聲明的語法格式:
<%! declaration; [ declaration; ]+ ... %>
或者,您也可以編寫與其等價的XML語句,就像下面這樣:
<jsp:declaration> 代碼片段</jsp:declaration>
程序示例:
<%! int i=0; %> <%! int a, b, c; %> <%! Circle a=new Circle(2.0); %>
JSP表達式
一個JSP表達式中包含的腳本語言表達式,先被轉化成String,然后插入到表達式出現的地方。
由于表達式的值會被轉化成String,所以您可以在一個文本行中使用表達式而不用去管它是否是HTML標簽。
表達式元素中可以包含任何符合Java語言規范的表達式,但是不能使用分號來結束表達式。
JSP表達式的語法格式:
<%=表達式 %>
同樣,您也可以編寫與之等價的XML語句:
<jsp:expression> 表達式</jsp:expression>
程序示例:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鳥教程(runoob.com)</title></head><body><p> 今天的日期是: <%=(new java.util.Date()).toLocaleString()%></p></body> </html>
運行后得到以下結果:
今天的日期是: 2016-6-25 13:40:07
JSP注釋
JSP注釋主要有兩個作用:為代碼作注釋以及將某段代碼注釋掉。
JSP注釋的語法格式:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鳥教程(runoob.com)</title></head><body><%-- 該部分注釋在網頁中不會被顯示--%> <p> 今天的日期是: <%=(new java.util.Date()).toLocaleString()%></p></body> </html>
運行后得到以下結果:
今天的日期是: 2016-6-25 13:41:26
不同情況下使用注釋的語法規則:
語法 | 描述 |
---|---|
<%-- 注釋 --%> | JSP注釋,注釋內容不會被發送至瀏覽器甚至不會被編譯 |
<!-- 注釋 --> | HTML注釋,通過瀏覽器查看網頁源代碼時可以看見注釋內容 |
<\% | 代表靜態 <%常量 |
%\> | 代表靜態 %> 常量 |
\' | 在屬性中使用的單引號 |
\" | 在屬性中使用的雙引號 |
JSP指令
JSP指令用來設置與整個JSP頁面相關的屬性。
JSP指令語法格式:
<%@ directive attribute="value" %>
這里有三種指令標簽:
指令 | 描述 |
---|---|
<%@ page ... %> | 定義頁面的依賴屬性,比如腳本語言、error頁面、緩存需求等等 |
<%@ include ... %> | 包含其他文件 |
<%@ taglib ... %> | 引入標簽庫的定義,可以是自定義標簽 |
JSP行為
JSP行為標簽使用XML語法結構來控制servlet引擎。它能夠動態插入一個文件,重用JavaBean組件,引導用戶去另一個頁面,為Java插件產生相關的HTML等等。
行為標簽只有一種語法格式,它嚴格遵守XML標準:
<jsp:action_name attribute="value" />
行為標簽基本上是一些預先就定義好的函數,下表羅列出了一些可用的JSP行為標簽::
語法 | 描述 |
---|---|
jsp:include | 用于在當前頁面中包含靜態或動態資源 |
jsp:useBean | 尋找和初始化一個JavaBean組件 |
jsp:setProperty | 設置 JavaBean組件的值 |
jsp:getProperty | 將 JavaBean組件的值插入到 output中 |
jsp:forward | 從一個JSP文件向另一個文件傳遞一個包含用戶請求的request對象 |
jsp:plugin | 用于在生成的HTML頁面中包含Applet和JavaBean對象 |
jsp:element | 動態創建一個XML元素 |
jsp:attribute | 定義動態創建的XML元素的屬性 |
jsp:body | 定義動態創建的XML元素的主體 |
jsp:text | 用于封裝模板數據 |
JSP隱含對象
JSP支持九個自動定義的變量,江湖人稱隱含對象。這九個隱含對象的簡介見下表:
對象 | 描述 |
---|---|
request | HttpServletRequest類的實例 |
response | HttpServletResponse類的實例 |
out | PrintWriter類的實例,用于把結果輸出至網頁上 |
session | HttpSession類的實例 |
application | ServletContext類的實例,與應用上下文有關 |
config | ServletConfig類的實例 |
pageContext | PageContext類的實例,提供對JSP頁面所有對象以及命名空間的訪問 |
page | 類似于Java類中的this關鍵字 |
Exception | Exception類的對象,代表發生錯誤的JSP頁面中對應的異常對象 |
控制流語句
JSP提供對Java語言的全面支持。您可以在JSP程序中使用Java API甚至建立Java代碼塊,包括判斷語句和循環語句等等。
判斷語句
If…else塊,請看下面這個例子:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%! int day=3; %> <!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鳥教程(runoob.com)</title></head><body><h3>IF...ELSE 實例</h3><% if (day==1 | day==7) { %> <p>今天是周末</p><% } else { %> <p>今天不是周末</p><% } %></body> </html>
運行后得到以下結果:
IF...ELSE 實例今天不是周末
現在來看看switch…case塊,與if…else塊有很大的不同,它使用out.println(),并且整個都裝在腳本程序的標簽中,就像下面這樣:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%! int day=3; %> <!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鳥教程(runoob.com)</title></head><body><h3>SWITCH...CASE 實例</h3><% switch(day) {case 0: out.println("星期天"); break;case 1: out.println("星期一"); break;case 2: out.println("星期二"); break;case 3: out.println("星期三"); break;case 4: out.println("星期四"); break;case 5: out.println("星期五"); break;default: out.println("星期六");}%></body> </html>
瀏覽器訪問,運行后得出以下結果:
SWITCH...CASE 實例星期三
循環語句
在JSP程序中可以使用Java的三個基本循環類型:for,while,和 do…while。
讓我們來看看for循環的例子,以下輸出的不同字體大小的"我愛學習":
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%! int fontSize; %> <!DOCTYPE html><html><head><meta charset="utf-8"><title>我愛學習(run.com)</title></head><body><h3>For 循環實例</h3><%for ( fontSize=1; fontSize <=3; fontSize++){ %> <font color="green" size="<%=fontSize %>"> 我愛學習 </font><br /><%}%></body> </html>
將上例改用while循環來寫:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%! int fontSize; %> <!DOCTYPE html><html><head><meta charset="utf-8"><title>我愛學習(run.com)</title></head><body><h3>While 循環實例</h3><%while ( fontSize <=3){ %> <font color="green" size="<%=fontSize %>"> 我愛學習 </font><br /><%fontSize++;%><%}%></body> </html>JSP運算符
JSP支持所有Java邏輯和算術運算符。
下表羅列出了JSP常見運算符,優先級從高到底:
類別 | 操作符 | 結合性 |
---|---|---|
后綴 | () [] . (點運算符) | 左到右 |
一元 | ++ - - ! ~ | 右到左 |
可乘性 | * / % | 左到右 |
可加性 | + - | 左到右 |
移位 | >> >>> << | 左到右 |
關系 | > >=< <= | 左到右 |
相等/不等 | ==!= | 左到右 |
位與 | & | 左到右 |
位異或 | ^ | 左到右 |
位或 | | | 左到右 |
邏輯與 | && | 左到右 |
邏輯或 | || | 左到右 |
條件判斷 | ?: | 右到左 |
賦值 | =+=-=*=/=%=>>=<<=&=^=|= | 右到左 |
逗號 | , | 左到右 |
JSP 字面量
JSP語言定義了以下幾個字面量:
布爾值(boolean):true 和 false;
整型(int):與 Java 中的一樣;
浮點型(float):與 Java 中的一樣;
字符串(string):以單引號或雙引號開始和結束;
Null:null。
ava代碼:
package com.demo.action;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class InputGoAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String methodName=request.getParameter("method");
if ("saveUserInfo".equals(methodName)) {
return mapping.findForward("saveforward");
}
if ("checkUserInfo".equals(methodName)) {
return mapping.findForward("checkforward");
}
return null;
}
}
package com.demo.action;
import com.demo.dao.UserInfoDao;
import com.demo.form.UserInfoForm;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class UserInfoAction extends DispatchAction {
private UserInfoDao dao=null;
private UserInfoForm userInfoForm=null;
public ActionForward saveUserInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
userInfoForm=(UserInfoForm) form;
dao=new UserInfoDao();
if (dao.saveUserInfo(userInfoForm)) {
request.getSession().setAttribute("userInfo", userInfoForm);
request.setAttribute("information", "注冊用戶成功!");
}
else {
request.setAttribute("information", "您注冊用戶失敗!");
}
return mapping.findForward("opeationUserInfo");
}
public ActionForward checkUserInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HttpSession session=request.getSession();
userInfoForm=(UserInfoForm) form;
dao=new UserInfoDao();
String account=userInfoForm.getAccount();
String password=com.demo.tools.Encrypt.encodeMD5(userInfoForm.getPassword());
userInfoForm=dao.queryUserInfo(account);
if (null==userInfoForm) {
request.setAttribute("information", "用戶名不存在!");
}
else if (!userInfoForm.getPassword().equals(password)) {
request.setAttribute("information", "用戶登錄密碼有誤!");
}
else {
request.setAttribute("information", "用戶登錄成功!");
session.setAttribute("userInfo", userInfoForm);
}
return mapping.findForward("opeationUserInfo");
}
}
package com.demo.check;
import com.demo.dao.UserInfoDao;
import com.demo.form.UserInfoForm;
public class CheckOutData {
/**
* 校驗用戶名在數據表中是否存在
* @param account
* @return
*/
public static String isCheckUser(String account) {
String result="";
if (null !=account || !account.equals("")) {
UserInfoDao dao=new UserInfoDao();
UserInfoForm userInfo=dao.queryUserInfo(account);
if (null !=userInfo) {
result="該用戶不能使用!";
}
}
return result;
}
/**
* 校驗Email地址是否正確
* @param email
* @return
*/
public static String idCheckEmail(String email) {
String result="";
if (null !=email || !email.equals("")) {
boolean flag=com.demo.tools.Encrypt.checkEmail(email);
if (!flag) {
result="您輸入的Email地址不合法!";
}
}
return result;
}
}
package com.demo.dao;
import com.demo.form.UserInfoForm;
import com.demo.tools.JDBConnection;
import java.sql.ResultSet;
import java.sql.SQLException;
public class UserInfoDao {
private JDBConnection connection=null;
private UserInfoForm userInfoForm=null;
public UserInfoDao() {
connection=new JDBConnection();
}
/**
* 保存用戶信息
* @param userInfoForm
* @return
*/
public boolean saveUserInfo(UserInfoForm userInfoForm) {
StringBuilder sql=new StringBuilder();
sql.append("insert into t_userinfo2 (account,password,email,sign,question,result,name,sex,fromspace,qq,introduce) ");
sql.append("values(?,?,?,?,?,?,?,?,?,?,?)");
boolean flag=false;
String[] pam={
userInfoForm.getAccount(),
com.demo.tools.Encrypt.encodeMD5(userInfoForm.getPassword()),
userInfoForm.getEmail(), userInfoForm.getSign(),userInfoForm.getQuestion(),
userInfoForm.getResult(), userInfoForm.getName(),userInfoForm.getSex(),
userInfoForm.getFromspace(),userInfoForm.getQq(), userInfoForm.getIntroduce()};
if (connection.updateData(sql.toString(),pam)) {
flag=true;
}
return flag;
}
/**
* 查詢用戶信息
* @param account
* @return
*/
public UserInfoForm queryUserInfo(String account) {
try {
String sql="select * from t_userinfo2 where account=?";
String[] pam={account};
ResultSet rs=connection.queryByPsStatement(sql,pam);
while (rs.next()) {
userInfoForm=new UserInfoForm();
userInfoForm.setId(rs.getInt(1));
userInfoForm.setAccount(rs.getString(2));
userInfoForm.setPassword(rs.getString(3));
userInfoForm.setEmail(rs.getString(4));
userInfoForm.setSign(rs.getString(5));
userInfoForm.setQuestion(rs.getString(6));
userInfoForm.setResult(rs.getString(7));
userInfoForm.setName(rs.getString(8));
userInfoForm.setSex(rs.getString(9));
userInfoForm.setFromspace(rs.getString(10));
userInfoForm.setQq(rs.getString(11));
userInfoForm.setIntroduce(rs.getString(12));
}
}
catch (SQLException ex) {
return null;
}
finally {
connection.closeAll();
}
return userInfoForm;
}
}
package com.demo.form;
import com.demo.dao.UserInfoDao;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class UserInfoForm extends ActionForm {
private Integer id=-1;
private String code="";
private String account="";
private String password="";
private String repassword="";
private String email="";
private String sign="0";
private String question="";
private String result="";
private String name="";
private String sex="男";
private String fromspace="";
private String qq="";
private String introduce="";
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account=account;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email=email;
}
public String getFromspace() {
return fromspace;
}
public void setFromspace(String fromspace) {
this.fromspace=fromspace;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id=id;
}
public String getIntroduce() {
return introduce;
}
public void setIntroduce(String introduce) {
this.introduce=introduce;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name=name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password=password;
}
public String getQq() {
return qq;
}
public void setQq(String qq) {
this.qq=qq;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question=question;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result=result;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex=sex;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign=sign;
}
public String getRepassword() {
return repassword;
}
public void setRepassword(String repassword) {
this.repassword=repassword;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code=code;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors=new ActionErrors();
String requestString=request.getQueryString();
HttpSession session=request.getSession();
String rand=(String)session.getAttribute("rand");
if (requestString.equalsIgnoreCase("method=saveUserInfo")) {
if (null==code || code.equals("")) {
errors.add("code", new ActionMessage("request.error.code"));
}
else if (!code.equals(rand)) {
errors.add("code", new ActionMessage("request.error.decode"));
}
if (null==account || account.equals("")) {
errors.add("account",
new ActionMessage("request.error.account"));
}
else {
UserInfoDao dao=new UserInfoDao();
if (null !=dao.queryUserInfo(account)) {
errors.add("account", new ActionMessage("request.error.account1"));
}
}
if (null==password || password.equals("")) {
errors.add("password", new ActionMessage(
"request.error.password"));
}
if (null==repassword || repassword.equals("")) {
errors.add("repassword", new ActionMessage(
"request.error.repassword"));
}
if (!repassword.equals(password)) {
errors.add("repassword", new ActionMessage(
"request.error.dfpassword"));
}
if (null==email || email.equals("")) {
errors.add("email", new ActionMessage("request.error.email"));
} else if (!com.demo.tools.Encrypt.checkEmail(email)) {
errors.add("email", new ActionMessage("request.error.email1"));
}
if (question.length() !=0) {
if (null==result || result.equals("")) {
errors.add("result", new ActionMessage(
"request.error.result"));
}
}
}
if (requestString.equalsIgnoreCase("method=checkUserInfo")) {
if (null==account || account.equals("")) {
errors.add("account",
new ActionMessage("request.error.account"));
}
if (null==password || password.equals("")) {
errors.add("password", new ActionMessage(
"request.error.password"));
}
if (null==code || code.equals("")) {
errors.add("code", new ActionMessage("request.error.code"));
}
else if (!code.equals(rand)) {
errors.add("code", new ActionMessage("request.error.decode"));
}
}
return errors;
}
/**
* Method reset
*
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
}
package com.demo.tools;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Encrypt {
public static String encodeMD5(String str) {
if (str==null) {
return null;
}
StringBuilder sb=new StringBuilder();
try {
MessageDigest code=MessageDigest.getInstance("MD5");
code.update(str.getBytes());
byte[] bs=code.digest();
for (int i=0; i < bs.length; i++) {
int v=bs[i] & 0xFF;
if (v < 16) {
sb.append(0);
}
sb.append(Integer.toHexString(v));
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return sb.toString().toUpperCase();
}
public static boolean checkEmail(String email) {
String regex="[a-zA-Z][\\w_]+@\\w+(\\.\\w+)+";
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(email);
return m.matches();
}
}
package com.demo.tools;
import java.sql.*;
public class JDBConnection {
private final String dbDriver="com.mysql.jdbc.Driver";
private final String url="jdbc:mysql://localhost:3306/testdb?useUnicode&characterEncodiing=utf-8&useSSL=true&rewriteBatchedStatements=true";
private final String userName="root";
private final String password="root";
private ResultSet rs=null;
private Statement stmt=null;
private Connection con=null;
private PreparedStatement preparedStatement=null;
public JDBConnection() {
try {
Class.forName(dbDriver).newInstance();
}
catch (Exception ex) {
System.out.println("數據庫加載失敗");
}
}
private boolean creatConnection() {
try {
con=DriverManager.getConnection(url, userName, password);
con.setAutoCommit(true);
return true;
}
catch (SQLException e) {
System.out.println(e.getMessage());
return false;
}
}
private void createPsStatement(String sql) {
creatConnection();
try {
System.out.println("創建PrepareStatement通道對象。。。");
preparedStatement=con.prepareStatement(sql);
}
catch (SQLException e) {
System.out.println("創建PrepareStatement通道對象失敗。。。");
e.printStackTrace();
}
}
private void bundle(String[] parm) {
//判斷數組Parm是否為空
if (parm !=null) {
//通過for循環將參數綁定起來
for (int i=0; i < parm.length; i++) {
try {
System.out.println( "進行參數的綁定。。。");
preparedStatement.setString(i + 1, parm[i]);
}
catch (SQLException e) {
System.out.println("綁定參數失敗。。。");
e.printStackTrace();
}
}
}
}
public ResultSet queryByPsStatement(String sql,String[] pram) {
createPsStatement(sql);
bundle(pram);
try {
System.out.println("采用PrepareStatement方法執行sql查詢語句。。。");
rs=preparedStatement .executeQuery();
}
catch (SQLException e) {
System.out.println("采用PrepareStatement方法執行sql查詢語句失敗");
e.printStackTrace();
}
return rs;
}
public Boolean updateData(String sql,String[] parm) {
//創建通道
createPsStatement(sql);
//綁定參數
bundle(parm);
int row=0;
try {
System.out.println("修改數據中。。。");
row=preparedStatement.executeUpdate();
} catch (SQLException e) {
System.out.println("修改數據失敗。。。");
e.printStackTrace();
}
boolean res=false;
if (row > 0) {
res=true;
}
return res;
}
public void closeAll() {
if (rs !=null) {
try {
System.out.println("關閉resultSet。。。");
rs.close();
} catch (SQLException e) {
System.out.println("關閉resultSet異常。。。");
e.printStackTrace();
}
}
if (stmt !=null) {
try {
System.out.println("關閉statement。。。");
stmt.close();
} catch (SQLException e) {
System.out.println("關閉statement異常。。。");
e.printStackTrace();
}
}
if (preparedStatement !=null) {
try {
System.out.println("關閉preparestatement。。。");
preparedStatement .close();
} catch (SQLException e) {
System.out.println("關閉preparestatement異常。。。");
e.printStackTrace();
}
}
if (con !=null) {
try {
System.out.println("關閉connection。。。");
con.close();
} catch (SQLException e) {
System.out.println("關閉connection異常。。。");
e.printStackTrace();
}
}
}
}
package com.demo.tools;
import org.apache.struts.action.RequestProcessor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
public class SelfRequestProcessor extends RequestProcessor {
public SelfRequestProcessor() {
}
protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
super.processPreprocess(request, response);
try {
request.setCharacterEncoding("UTF-8");
}
catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
return true;
}
}
request.error.code=\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801\uff01
request.error.decode=\u60a8\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u4e0d\u6b63\u786e\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01
request.error.account=\u8bf7\u8f93\u5165\u7528\u6237\u540d\uff01
request.error.account1=\u60a8\u8f93\u5165\u7684\u7528\u6237\u540d\u5df2\u5b58\u5728\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01
request.error.password=\u8bf7\u60a8\u8f93\u5165\u767b\u5f55\u5bc6\u7801\uff01
request.error.repassword=\u8bf7\u60a8\u8f93\u5165\u786e\u8ba4\u5bc6\u7801\uff01
request.error.dfpassword=\u60a8\u8f93\u5165\u7684\u5bc6\u7801\u4e0e\u786e\u8ba4\u5bc6\u7801\u4e0d\u540c\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01
request.error.email=\u8bf7\u60a8\u8f93\u5165Email\u5730\u5740\uff01
request.error.result=\u8bf7\u60a8\u8f93\u5165\u95ee\u9898\u7684\u7b54\u6848\uff01
request.error.email1=\u60a8\u8f93\u5165\u7684Email\u5730\u5740\u4e0d\u5408\u6cd5\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01
CSS代碼:
<!--
td {
font-size: 9pt;color: #000000;
}
a:hover {
font-size: 9pt;
color: #FF0000;
}
a {
font-size: 9pt;
text-decoration: none;
color: #000000;
}
img{
border:0;
}
.img1{
border:1px;
}
.blue {
font-size: 9pt;
color: #034683;
}
.bgcolor {
font-size: 9pt;
color: #1980DB;
}
.btn_grey {
font-family: "宋體";
font-size: 9pt;
color: #333333;
background-color: #eeeeee;
cursor: hand;
padding:1px;
height:19px;
border-top: 1px solid #FFFFFF;
border-right:1px solid #666666;
border-bottom: 1px solid #666666;
border-left: 1px solid #FFFFFF;
}
input{
font-family: "宋體";
font-size: 9pt;
color: #333333;
border: 1px solid #999999;
}
.word_white{
color:#FFFFFF;
}
.word_deepgrey{
color:#999999;
}
.word_orange{
color:#FF6600;
}
.word_green{
color:#FEECEA;
}
.noborder{
border:none;
}
.word_gray{
color:#dddddd;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
textarea {
font-family: "宋體";
font-size: 9pt;
color: #333333;
border: 1px solid #999999;
}
hr{
border-style:dashed;
color:#CCCCCC;
}
.tableBorder_lb {
border: #D8D8D8 1px solid;
border-top-style:none;
border-bottom-style:none;
}
.a1:link {
color: #FFFFFF;
TEXT-DECORATION: none;
font-size:9pt;
}
.a1:visited {
color: #FFFFFF;
TEXT-DECORATION: none;
font-size:9pt;
}
.a1:active {
color: #FFFFFF;
TEXT-DECORATION: none;
font-size:9pt;
}
.a1:hover {
color: #FF0000;
font-size:9pt;
}
.a2:link {
color: #FF0000;
TEXT-DECORATION: none ;
font-size:9pt;
}
.a2:visited {
color: #FF0000;
TEXT-DECORATION: none;
font-size:9pt;
}
.a2:active {
color: #FF0000;
font-size:9pt;
text-decoration:none;
}
.a2:hover {
color: #FFFFFF;
font-size:9pt;
}
.a3:link {
color: #FFFFFF;
TEXT-DECORATION: none ;
font-size:9pt;
}
.a3:visited {
color: #FFFFFF;
TEXT-DECORATION: none;
font-size:9pt;
}
.a3:active {
color: #FFFFFF;
font-size:9pt;
text-decoration:none;
}
.a3:hover {
color: #FF0000;
font-size:9pt;
}
.a4:link {
color: #6C6C6E;
TEXT-DECORATION: none ;
font-size:10pt;
font-weight:bold;
}
.a4:visited {
color: #6C6C6E;
TEXT-DECORATION: none;
font-size:10pt;
font-weight:bold;
}
.a4:active {
color: #6C6C6E;
font-size:10pt;
text-decoration:none;
font-weight:bold;
}
.a4:hover {
color: #FF0000;
font-size:10pt;
font-weight:bold;
}
.lineline{
line-height:1.5em;
}
.a5:link {
color: #F9B77D;
TEXT-DECORATION: none ;
font-size:10pt;
font-weight:bold;
}
.a5:visited {
color: #F9B77D;
TEXT-DECORATION: none;
font-size:10pt;
font-weight:bold;
}
.a5:active {
color: #F9B77D;
font-size:10pt;
text-decoration:none;
font-weight:bold;
}
.a5:hover {
color: #FF0000;
font-size:10pt;
font-weight:bold;
}
.a6:link {
color: #FF0000;
TEXT-DECORATION: underline ;
font-size:9pt;
font-weight:bold;
}
.a6:visited {
color: #FF0000;
TEXT-DECORATION: underline;
font-size:9pt;
font-weight:bold;
}
.a6:active {
color: #FF0000;
font-size:9pt;
text-decoration: underline;
font-weight:bold;
}
.a6:hover {
color: #000000;
font-size:9pt;
font-weight:bold;
}
.lineline{
line-height:1.5em;
}
.a7:link {
color: #FF0000;
TEXT-DECORATION: none ;
font-size:10pt;
font-weight:bold;
}
.a7:visited {
color: #FF0000;
TEXT-DECORATION: none;
font-size:10pt;
font-weight:bold;
}
.a7:active {
color: #FF0000;
font-size:10pt;
text-decoration: none;
font-weight:bold;
}
.a7:hover {
color: #000000;
font-size:10pt;
font-weight:bold;
}
.line{
color:#FFE400;
font-size:9pt;
line-height:12pt;
}
select{
font-family: "宋體";
font-size: 9pt;
color: #333333;
border: 1px solid #999999;
}
.cannelBorder{
border: 0px solid #999999;
}
.inputinput{
font-family: "宋體";
font-size: 9pt;
color: #333333;
border: 1px solid #67A0CD;
}
JSP頁面:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:directive.page import="com.demo.form.UserInfoForm"/>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>工作室—用戶登錄</title>
<link href="css/style.css" type="text/css" rel="stylesheet" />
<script language="javascript">
function reload(){
document.getElementById("checkCode").src="image.jsp?nocache="+new Date().getTime();
}
</script>
</head>
<body>
<table width="840" height="71" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_01.png">
<tr>
<td width="236"> </td>
<td width="604" valign="top"><table width="573" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="573" height="43" valign="bottom">
<a href="#" class="a2">首頁</a>
<a href="#" class="a1">Cisco</a>
<a href="#" class="a1">Windows</a>
<a href="#" class="a1">Linux</a>
<a href="#" class="a1">Java</a>
<a href="#" class="a1">.Net</a>
<a href="#" class="a1">互聯網</a>
<a href="#" class="a1">IT動態網</a>
<a href="#" class="a1">網絡設備</a>
<a href="#" class="a1">服務器</a>
</td>
</tr>
<tr>
<td height="24">
<a href="#" class="a1"> IDC</a>
<a href="#" class="a1">IT技術</a>
<a href="#" class="a1">專題</a>
<a href="#" class="a1">培訓</a>
<a href="#" class="a1">下載</a>
<a href="#" class="a1">搜索</a>
<a href="#" class="a1">虛擬考場</a>
<a href="#" class="a1">遠程培訓</a>
<a href="#" class="a1">周刊</a>
<a href="#" class="a1">博客</a>
</td>
</tr>
</table></td>
</tr>
</table>
<table width="840" height="131" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_02.gif">
<tr>
<td width="746"> </td>
<td width="94">
<a href="#" class="a3">About US</a><br>
<br>
<a href="#" class="a3">Cortent US</a><br>
<br>
<a href="#" class="a3">Home</a></td>
</tr>
</table>
<%
UserInfoForm userInfoForm=null;
if(null==session.getAttribute("userInfo")){
%>
<table width="840" height="33" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_03.gif">
<tr>
<td>
<span class="STYLE1"><font color="6C6C6E">您尚未</font></span> <a href="#" class="a4">登錄</a> <a href="register.jsp" class="a4">注冊</a> | <a href="#" class="a4">推薦 </a> | <a href="#" class="a4">搜索 </a> | <a href="#" class="a4">社區服務</a> | <a href="#" class="a4">朋友圈</a> | <a href="#" class="a4">我的空間</a> | <a href="#" class="a4">幫助</a> </td>
</tr>
</table>
<table width="840" border="0" align="center" cellpadding="0" cellspacing="0" class="tableBorder_lb">
<tr>
<td height="104" valign="top">
<br>
<table width="249" height="30" border="0" cellpadding="0" cellspacing="0" background="images/land_07.gif">
<tr>
<td width="35"> </td>
<td width="214"><span class="STYLE9">工作室登錄窗口</span></td>
</tr>
</table>
<table width="249" height="137" border="0" cellpadding="0" cellspacing="0" background="images/land_08.gif">
<tr>
<td width="24"> </td>
<td width="225">
<br>
<table width="203" border="0">
<html:form action="userInfo.do?method=checkUserInfo">
<tr>
<td width="53" height="30"> 用戶名: </td>
<td width="140"><html:text property="account" styleClass="inputinput"/></td>
</tr>
<tr>
<td height="30"> 密 碼:</td>
<td><html:password property="password" styleClass="inputinput"/></td>
</tr>
<tr>
<td height="30"> 驗證碼: </td>
<td><html:text property="code" styleClass="inputinput"/></td>
</tr>
<tr>
<td height="30"> </td>
<td><table width="131" border="0">
<tr>
<td width="74">
<img border=0 src="image.jsp" id="checkCode"/>
</td>
<td width="47">
<a href="#" class="a6" onClick="reload()">看不清</a>
</td>
</tr>
</table></td>
</tr>
<tr>
<td height="30"> </td>
<td>
<html:submit value=" " style="background-image:url(images/land_10.gif);border:0;width:54;height:20"/>
<html:button value=" " property="register"
style="background-image:url(images/land_11.gif);
border:0;width:54;height:20"
onclick="javasrcipt:window.location.href='register.jsp'">
</html:button>
</td>
</tr>
<tr>
<td> </td>
<td>
<html:errors property="account"/><br>
<html:errors property="password"/><br>
<html:errors property="code"/><br>
</td>
</tr>
</html:form>
</table>
</td>
</tr>
</table>
<img src="images/land_09.png" width="249" height="57"></td>
<td width="601" valign="top">
<br>
<table width="562" height="28" border="0" cellpadding="0" cellspacing="0" background="images/land_05.gif">
<tr>
<td width="37"> </td>
<td width="525"><span class="STYLE6">關于工作室</span></td>
</tr>
</table>
<table width="484" height="94" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="462" height="94">
<span class="lineline">
<span class="STYLE7">
<span class="STYLE8">工作室</span>
</span>是由幾個志同道合的朋友一起創辦的集博客、論壇、空間、新聞等8大功能于一身的門戶網站機構、先已擁有800萬固定網友...... </span>
</td>
</tr>
</table>
<table width="148" height="19" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td height="19">
<a href="#" class="a5"><img src="images/land_19.gif" width="49" height="15"></a>
</td>
</tr>
</table><br><br>
<table width="562" height="28" border="0" cellpadding="0" cellspacing="0" background="images/land_05.gif">
<tr>
<td width="37"> </td>
<td width="525"><span class="STYLE6">打造國內最酷個人空間</span></td>
</tr>
</table>
<table width="446" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="208" height="45" valign="bottom" class="word">
<span class="lineline"><strong class="STYLE8">空間</strong><br>
提供50MB免費空間,支持MySQL數據庫</span>
</td>
<td width="189" valign="bottom" class="word">
<span class="lineline">
<strong class="STYLE8">空間</strong><br>30位斑竹熱聘中....</span>
</td>
</tr>
</table>
<table width="446" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="234" height="54" valign="bottom" class="word">
<span class="lineline"><strong class="STYLE8">博客</strong>
<br>新近研發博客搬家工具,方便之門</span>
</td>
<td width="212" valign="bottom" class="word"><span class="lineline">
<strong class="STYLE8">下載</strong>
<br>500萬資源供您下載</span>
</td>
</tr>
</table>
<table width="148" height="19" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td height="19"><a href="#" class="a5">
<img src="images/land_19.gif" width="49" height="15"></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%}else{
userInfoForm=(UserInfoForm)session.getAttribute("userInfo");
%>
<table width="840" height="33" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_03.gif">
<tr>
<td align="right">
<span class="STYLE1"><font color="6C6C6E">您已經登錄</font></span>
<a href="dealwith.jsp?sign=3" class="a4">如果想退出,請單擊此鏈接</a> |
<a href="#" class="a4">朋友圈</a> |
<a href="#" class="a4">我的空間</a> |
<a href="#" class="a4">幫助 </a>
</td>
</tr>
</table>
<table width="840" height="62" border="0" align="center" cellpadding="0" cellspacing="0" class="tableBorder_lb">
<tr>
<td width="664" align="center">
<br>
<table width="651" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_14.gif">
<tr>
<td height="30" colspan="2" background="images/land_13.gif"> 顯示用戶信息</td>
</tr>
<tr>
<td width="120" height="30" align="right"> 用戶名:</td>
<td width="531"> <%=userInfoForm.getAccount() %></td>
</tr>
<tr>
<td height="30" align="right"> Email:</td>
<td height="30"> <%=userInfoForm.getEmail() %></td>
</tr>
<tr>
<td height="30" align="right"> 昵 稱:</td>
<td height="30"> <%=userInfoForm.getName() %></td>
</tr>
<tr>
<td height="30" align="right"> 性 別:</td>
<td height="30"> <%=userInfoForm.getSex() %></td>
</tr>
<tr>
<td height="30" align="right"> 來 自:</td>
<td height="30"> <%=userInfoForm.getFromspace() %></td>
</tr>
<tr>
<td height="30" align="right"> QQ:</td>
<td height="30"> <%=userInfoForm.getQq() %></td>
</tr>
<tr>
<td height="30" align="right"> 自我介紹:</td>
<td height="30"> <%=userInfoForm.getIntroduce() %></td>
</tr>
<tr>
<td colspan="2">
<img src="images/land_15.gif" width="651" height="5">
</td>
</tr>
</table>
<br>
</td>
<td width="174" valign="bottom">
<div align="right">
<img src="images/land_12.png" width="173" height="57">
</div>
</td>
</tr>
</table>
<%} %>
<table width="840" height="48" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_06.gif">
<tr>
<td align="center">
<span class="STYLE3"><br>
<span class="STYLE12"></span>
</span>
</td>
</tr>
</table>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>工作室—用戶注冊</title>
<link href="css/style.css" type="text/css" rel="stylesheet" />
<script language="javascript">
var http_request=false;
function createRequest(url,alert) {
//初始化對象并發出XMLHttpRequest請求
http_request=false;
if (window.XMLHttpRequest) {
// Mozilla或其他除IE以外的瀏覽器
http_request=new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType("text/xml");
}
}
else if (window.ActiveXObject) {
// IE瀏覽器
try {
http_request=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request=new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert("不能創建XMLHTTP實例!");
return false;
}
http_request.onreadystatechange=alert; //指定響應方法
//發出HTTP請求
http_request.open("GET", url, true);
http_request.send(null);
}
function alertAccount() { //處理服務器返回的信息
if (http_request.readyState==4) {
if (http_request.status==200) {
account1.innerHTML=http_request.responseText;
} else {
alert('您請求的頁面發現錯誤');
}
}
}
function alertEmail() { //處理服務器返回的信息
if (http_request.readyState==4) {
if (http_request.status==200) {
email.innerHTML=http_request.responseText;
} else {
alert('您請求的頁面發現錯誤');
}
}
}
function alertRepassword() { //處理服務器返回的信息
if (http_request.readyState==4) {
if (http_request.status==200) {
repassword.innerHTML=http_request.responseText;
} else {
alert('您請求的頁面發現錯誤');
}
}
}
function alertCode() { //處理服務器返回的信息
if (http_request.readyState==4) {
if (http_request.status==200) {
code.innerHTML=http_request.responseText;
} else {
alert('您請求的頁面發現錯誤');
}
}
}
</script>
<script language="javascript">
function F_code(code){
createRequest("dealwith.jsp?sign=0&code="+code,alertCode);
}
function F_account(account){
createRequest("dealwith.jsp?sign=1&account="+account,alertAccount);
}
function F_email(email){
createRequest("dealwith.jsp?sign=2&email="+email,alertEmail);
}
function F_repassword(repassword){
var password=userInfoForm.password.value;
createRequest("dealwith.jsp?sign=4&&password="+password+"&repassword="+repassword,alertRepassword);
}
function reload(){
document.getElementById("checkCode").src="image.jsp?nocache="+new Date().getTime();
}
</script>
</head>
<body>
<table width="840" height="71" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_01.png">
<tr>
<td width="236"> </td>
<td width="604" valign="top">
<table width="573" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="573" height="43" valign="bottom">
<a href="#" class="a2">首頁</a>
<a href="#" class="a1">Cisco</a>
<a href="#" class="a1">Windows</a>
<a href="#" class="a1">Linux</a>
<a href="#" class="a1">Java</a>
<a href="#" class="a1">.Net</a>
<a href="#" class="a1">互聯網</a>
<a href="#" class="a1">IT動態網</a>
<a href="#" class="a1">網絡設備</a>
<a href="#" class="a1">服務器</a>
</td>
</tr>
<tr>
<td height="24">
<a href="#" class="a1"> IDC</a>
<a href="#" class="a1">IT技術</a>
<a href="#" class="a1">專題</a>
<a href="#" class="a1">培訓</a>
<a href="#" class="a1">下載</a>
<a href="#" class="a1">搜索</a>
<a href="#" class="a1">虛擬考場</a>
<a href="#" class="a1">遠程培訓</a>
<a href="#" class="a1">周刊</a>
<a href="#" class="a1">博客</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="840" height="131" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_02.gif">
<tr>
<td width="746"> </td>
<td width="94">
<a href="#" class="a3">About US</a><br>
<br>
<a href="#" class="a3">Cortent US</a><br>
<br>
<a href="#" class="a3">Home </a></td>
</tr>
</table>
<table width="840" height="33" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_03.gif">
<tr>
<td width="645"> </td>
<td width="195">
<span class="STYLE2">
<span class="STYLE3">游客:</span>
</span>
<a href="register.jsp" class="a4">注冊</a> |
<a href="index.jsp" class="a4">登錄</a> |
<a href="#" class="a4">幫助</a>
</td>
</tr>
</table>
<table width="840" border="0" align="center" cellpadding="0" cellspacing="0" class="tableBorder_lb">
<tr>
<td width="789" height="129">
<br>
<table width="651" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_14.gif">
<html:form action="userInfo.do?method=saveUserInfo">
<tr>
<td height="30" colspan="3" background="images/land_13.gif"> 注冊</td>
</tr>
<tr>
<td height="30" colspan="3" align="center">
<span class="STYLE5">以 下 條 目 注 冊 用 戶 必 須 填 寫</span>
</td>
</tr>
<tr>
<td width="158" height="40" align="right"> 驗證碼:</td>
<td>
<html:text property="code" onkeydown="F_code(this.value)"
onkeypress="F_code(this.value)" onkeyup="F_code(this.value)"/>
</td>
<td>
<table width="322" border="0">
<tr>
<td width="52" height="34">
<a href="#" onClick="reload();">
<img border=0 src="image.jsp" id="checkCode">
</a>
</td>
<td width="260" id="code">
<html:errors property="code"/> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="40" align="right"> 用戶名:</td>
<td width="159" height="40">
<html:text property="account" onkeydown="F_account(this.value)"
onkeypress="F_account(this.value)" onkeyup="F_account(this.value)"/>
</td>
<td width="334" id="account1">
<html:errors property="account"/> </td>
</tr>
<tr>
<td height="40" align="right"> 密碼:</td>
<td height="40"><html:password property="password"/></td>
<td height="40" id="password">
<html:errors property="password"/> </td>
</tr>
<tr>
<td height="40" align="right"> 確認密碼:</td>
<td height="40">
<html:password property="repassword" onkeydown="F_repassword(this.value)"
onkeypress="F_repassword(this.value)" onkeyup="F_repassword(this.value)"/>
</td>
<td height="40" id="repassword">
<html:errors property="repassword"/> </td>
</tr>
<tr>
<td height="40" align="right"> Email地址:</td>
<td height="40">
<html:text property="email" onkeydown="F_email(this.value)"
onkeypress="F_email(this.value)" onkeyup="F_email(this.value)"/>
</td>
<td height="40" id="email">
<html:errors property="email"/> </td>
</tr>
<tr>
<td height="40" align="right"> 高級選項:</td>
<td height="40" colspan="2">
<html:checkbox value="1" property="sign" styleClass="cannelBorder"/>
顯示高級用戶設置選項</td>
</tr>
<tr>
<td height="30" colspan="3" align="center">
<span class="STYLE5">
以 下 條 目 注 冊 用 戶 選 填</span>
</td>
</tr>
<tr>
<td height="40" align="right"> 安全提問:</td>
<td height="40" colspan="2"><html:select property="question">
<html:option value="">請選擇問題</html:option>
<html:option value="你的母親叫什么名字">你的母親叫什么名字</html:option>
<html:option value="你的父親叫什么名字">你的父親叫什么名字</html:option>
<html:option value="你的孩子叫什么名字">你的孩子叫什么名字</html:option>
<html:option value="你畢業哪所高校">你畢業哪所高校</html:option>
<html:option value="你的出生日期是多少">你的出生日期是多少</html:option>
</html:select>
</td>
</tr>
<tr>
<td height="40" align="right"> 回答:</td>
<td height="40"><html:text property="result"/></td>
<td height="40"><html:errors property="result"/> </td>
</tr>
<tr>
<td height="40"align="right" > 昵稱:</td>
<td height="40"><html:text property="name"/></td>
<td height="40"> </td>
</tr>
<tr>
<td height="40" align="right"> 性別:</td>
<td height="40" colspan="2">
<html:radio property="sex" value="男" styleClass="cannelBorder"/>
男
<html:radio property="sex" value="女" styleClass="cannelBorder"/>
女</td>
</tr>
<tr>
<td height="40" align="right"> 來自:</td>
<td height="40"><html:text property="fromspace"/></td>
<td height="40"> </td>
</tr>
<tr>
<td height="40" align="right"> QQ:</td>
<td height="40"><html:text property="qq"/></td>
<td height="40"> </td>
</tr>
<tr>
<td height="40" align="right"> 自我介紹:</td>
<td height="40" colspan="2"><html:textarea property="introduce" cols="50"/></td>
</tr>
<tr align="center">
<td height="30" colspan="3">
<html:submit value=" " style="background-image:url(images/land_17.gif);border:0;width:54;height:20"/>
<html:reset value=" " style="background-image:url(images/land_16.gif);border:0;width:54;height:20"/>
</td>
</tr>
<tr align="center">
<td colspan="3">
<img src="images/land_15.gif">
</td>
</tr>
</html:form>
</table>
</td>
<td width="49" valign="bottom">
<img src="images/land_12.png" width="173" height="57">
</td>
</tr>
</table>
<table width="840" height="48" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_06.gif">
<tr>
<td align="center">
<span class="STYLE4"><br>
<span class="STYLE12"></span></span>
</td>
</tr>
</table>
</body>
</html>
<%@ page contentType="image/jpeg"
import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" language="java" %>
<%!Color getRandColor(int fc, int 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(r, g, b);
}%>
<%
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// 在內存中創建圖象
int width=60, height=20;
BufferedImage image=new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
// 獲取圖形上下文
Graphics g=image.getGraphics();
//生成隨機類
Random random=new Random();
// 設定背景色
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
//設定字體
g.setFont(new Font("Times New Roman", Font.PLAIN, 18));
// 隨機產生155條干擾線,使圖象中的認證碼不易被其它程序探測到
g.setColor(getRandColor(160, 200));
for (int i=0; i < 155; i++)
{
int x=random.nextInt(width);
int y=random.nextInt(height);
int xl=random.nextInt(12);
int yl=random.nextInt(12);
g.drawLine(x, y, x + xl, y + yl);
}
// 取隨機產生的認證碼(4位數字)
String sRand="";
for (int i=0; i < 4; i++)
{
String rand=String
.valueOf(random.nextInt(10));
sRand +=rand;
// 將認證碼顯示到圖象中
g.setColor(new Color(20 + random.nextInt(110),
20 + random.nextInt(110), 20 + random
.nextInt(110)));
//調用函數出來的顏色相同,可能是因為種子太接近,所以只能直接生成
g.drawString(rand, 13 * i + 6, 16);
}
// 將認證碼存入SESSION
session.setAttribute("rand", sRand);
// 圖象生效
g.dispose();
// 輸出圖象到頁面
ImageIO.write(image, "JPEG",response.getOutputStream());
out.clear();
out=pageContext.pushBody();
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<%
String information=null;
if(null!=request.getAttribute("information")){
information=(String)request.getAttribute("information");
}
%>
<title><%=information %></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<table width="840" height="71" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_01.png">
<tr>
<td width="236"> </td>
<td width="604" valign="top">
<table width="573" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="573" height="43" valign="bottom">
<a href="#" class="a2">首頁</a>
<a href="#" class="a1">Cisco</a>
<a href="#" class="a1">Windows</a>
<a href="#" class="a1">Linux</a>
<a href="#" class="a1">Java</a>
<a href="#" class="a1">.Net</a>
<a href="#" class="a1">互聯網</a>
<a href="#" class="a1">IT動態網</a>
<a href="#" class="a1">網絡設備</a>
<a href="#" class="a1">服務器</a>
</td>
</tr>
<tr>
<td height="24">
<a href="#" class="a1"> IDC</a>
<a href="#" class="a1">IT技術</a>
<a href="#" class="a1">專題</a>
<a href="#" class="a1">培訓</a>
<a href="#" class="a1">下載</a>
<a href="#" class="a1">搜索</a>
<a href="#" class="a1">虛擬考場</a>
<a href="#" class="a1">遠程培訓</a>
<a href="#" class="a1">周刊</a>
<a href="#" class="a1">博客</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="840" height="131" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_02.gif">
<tr>
<td width="746"> </td>
<td width="94">
<a href="#" class="a3">About US</a><br>
<br>
<a href="#" class="a3">Cortent US</a><br>
<br>
<a href="#" class="a3">Home </a>
</td>
</tr>
</table>
<table width="840" height="33" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_03.gif">
<tr>
<td width="666"> </td>
<td width="174"><a href="#" class="a4">顯示登錄結果</a></td>
</tr>
</table>
<table width="840" border="0" align="center" cellpadding="0" cellspacing="0" class="tableBorder_lb">
<tr>
<td width="789"><br>
<table width="651" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_14.gif">
<tr>
<td height="30" colspan="3" background="images/land_13.gif">
<span class="STYLE6">工作室 >> <%=information%>
</span>
</td>
</tr>
<tr>
<td width="334" colspan="3" align="center">
<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="549" height="150" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="539" height="148" align="center">
<table width="305" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="102">
<img src="images/land_18.gif" width="99" height="146">
</td>
<td width="203" valign="top">
<table width="196" border="0">
<tr>
<td width="186" height="67" valign="bottom">
<span class="STYLE6"><%=information%></span>
<a href="index.jsp" class="a7">請返回!</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr align="center">
<td colspan="3"><img src="images/land_15.gif"></td>
</tr>
</table>
</td>
<td width="49" valign="bottom">
<img src="images/land_12.png" width="173" height="57">
</td>
</tr>
</table>
<table width="840" height="48" border="0" align="center" cellpadding="0" cellspacing="0" background="images/land_06.gif">
<tr>
<td align="center">
<span class="STYLE4"><br>
<span class="STYLE12"></span>
</span>
</td>
</tr>
</table>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
request.setCharacterEncoding("utf-8");
Integer sign=Integer.parseInt(request.getParameter("sign"));
if (sign==0) {
String code=request.getParameter("code");
String rand=(String) session.getAttribute("rand");
if (null !=code||!code.equals("")) {
if (!code.equals(rand)) {
out.print("您輸入的校驗碼不正確");
}
}
}
if (sign==1) {
String account=request.getParameter("account");
account=new String(account.getBytes("ISO8859_1"), "utf-8");
System.out.print(account);
String result=com.demo.check.CheckOutData.isCheckUser(account);
out.print(result);
}
if (sign==2) {
String email=request.getParameter("email");
String result=com.demo.check.CheckOutData.idCheckEmail(email);
out.print(result);
}
if (sign==3) {
session.invalidate();
response.sendRedirect("index.jsp");
}
if (sign==4) {
String password=request.getParameter("password");
String repassword=request.getParameter("repassword");
if (repassword !=null || !repassword.equals("")) {
if (!password.equals(repassword)) {
out.print("您兩次輸入的密碼不一致");
}
}
}
%>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="userInfoForm" type="com.demo.form.UserInfoForm" />
</form-beans>
<action-mappings>
<action path="/inputGo" type="com.demo.action.InputGoAction"
name="userInfoForm" scope="request" validate="false">
<forward name="saveforward" path="/register.jsp" />
<forward name="checkforward" path="/index.jsp" />
</action>
<action path="/userInfo" type="com.demo.action.UserInfoAction"
name="userInfoForm" scope="request" parameter="method"
validate="true" input="/inputGo.do">
<forward name="opeationUserInfo" path="/showOperation.jsp" />
<forward name="queryAccount" path="/dealwith.jsp" />
</action>
</action-mappings>
<controller processorClass="com.demo.tools.SelfRequestProcessor" />
<message-resources parameter="ApplicationResources" />
</struts-config>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>registerDemo2</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
pom
*請認真填寫需求信息,我們會在24小時內與您取得聯系。