小白承包了一块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 肉鸡 被黑客入侵并被长期驻扎的计算机或服务器。可以随意控制,可以是任意系统的设备,对象可以是企业,个人,政府等等所有单位。
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小时内与您取得联系。