傲视苍穹
BlogJava
联系
聚合
管理
0 Posts :: 1 Stories :: 9 Comments :: 0 Trackbacks
留言簿
给我留言
查看公开留言
查看私人留言
文章档案
2007年12月 (1)
搜索
最新评论
1. re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
的撒旦
--去
2. re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在[未登录]
是 凤飞飞
--啊
3. re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
俄地方地方
--问问
4. re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
fsdf
--dadaad
5. re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在[未登录]
我页面总是获得不了 out.print( 0 );
这个值 什么原因呢
--过客
JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
1
<%
@ page language
=
"
java
"
pageEncoding
=
"
gbk
"
%>
2
<%
@ taglib uri
=
"
http://struts.apache.org/tags-bean
"
prefix
=
"
bean
"
%>
3
<%
@ taglib uri
=
"
http://struts.apache.org/tags-html
"
prefix
=
"
html
"
%>
4
5
<
html
>
6
<
head
>
7
<
title
>
JSP
for
RegisterForm form
</
title
>
8
<
SCRIPT LANGUAGE
=
"
JavaScript
"
>
9
function
nameChange()
{
10
11
if
(document.all.name.value
==
""
)
{
12
document.all.name1.innerHTML
=
"
<font size=2 color=red>!用户名不合法,不可以为空</font>
"
;
13
return
false
;
14
}
else
{
15
if
(document.all.name.value.length
<
5
||
document.all.name.value.length
>
50
)
{
16
document.all.name1.innerHTML
=
"
<font size=2 color=red>!用户名不合法,必须在5-50位之间</font>
"
;
17
return
false
;
18
}
else
{
19
var
req;
20
if
(window.ActiveXObject)
21
{
22
req
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
23
}
else
{
24
req
=
new
XMLHttpRequest();
25
}
26
27
if
(req)
{
28
req.onreadystatechange
=
function
()
{
29
30
if
(req.readyState
==
4
&&
req.status
==
200
)
{
//
判断状态,4是已发送,200已完成
31
32
if
(req.responseText
==
0
)
{
33
document.all.name1.innerHTML
=
"
<font size=2 color=blue>用户名可以正常使用!~</font>
"
;
34
return
true
;
35
}
else
if
(req.responseText
==
1
)
{
36
document.all.name1.innerHTML
=
"
<font size=2 color=red>!用户名已经被占用</font>
"
;
37
return
false
;
38
}
else
{
39
document.all.name1.innerHTML
=
"
<font size=2 color=blue>正在查询。。~</font>
"
;
40
return
false
;
41
}
42
}
43
}
44
req.open('POST', 'register.
do
?
test
=
1
&
name
=
'
+
document.all.name.value);
45
req.setRequestHeader('Content
-
Type', 'application
/
x
-
www
-
form
-
urlencoded');
46
req.send(
""
);
//
发送参数如果有参数req.send("username="+user_name);用request取得
47
}
48
}
49
}
50
}
51
function
pwdChange()
{
52
if
(document.all.pwd.value
==
""
)
{
53
document.all.pwd1.innerHTML
=
"
<font size=2 color=red>!密码不合法,不可以为空</font>
"
;
54
return
false
;
55
}
else
{
56
if
(document.all.pwd.value.length
<
5
||
document.all.pwd.value.length
>
20
)
{
57
document.all.pwd1.innerHTML
=
"
<font size=2 color=red>!密码不合法,长度必须在5-20位之间</font>
"
;
58
return
false
;
59
}
else
{
60
var
patrn
=/^
(([A
-
Z]
*|
[a
-
z]
*|
\d
*|
[
-
_\
~!
@#\$
%
\
^&
\
*
\.\(\)\[\]\
{\}
<>
\
?
\\\
/
\'\
"
]*)|.{0,5})$|\s/;
61
var password=document.all.pwd.value;
62
if(patrn.test(password)){
63
document.all.pwd1.innerHTML=
"
<
font size
=
2
color
=
red
>
!密码不合法,必须含有大写字母、小写字母、标点、数字中的至少两种。
</
font
>
"
;
64
return false;
65
}else{
66
document.all.pwd1.innerHTML=
"
<
font size
=
2
color
=
blue
>
密码合法
!~</
font
>
"
;
67
return true;
68
}
69
}
70
}
71
72
}
73
function rpwdChange(){
74
if(document.all.rpwd.value==
""
){
75
document.all.rpwd1.innerHTML=
"
<
font size
=
2
color
=
red
>
!确认密码不合法,不可以为空
</
font
>
"
;
76
return false;
77
}else{
78
if(document.all.rpwd.value!=document.all.pwd.value){
79
document.all.rpwd1.innerHTML=
"
<
font size
=
2
color
=
red
>
!确认密码必须和密码一致
!~</
font
>
"
;
80
return false;
81
}else{
82
document.all.rpwd1.innerHTML=
"
<
font size
=
2
color
=
blue
>
确认密码正确
!~</
font
>
"
;
83
return true;
84
}
85
}
86
}
87
88
function sub(path){
89
90
if(rpwdChange()&&pwdChange()&&nameChange()){
91
return true;
92
}else{
93
alert(
"
请正确填写信息!
"
);
94
return false;
95
96
}
97
}
98
</script>
99
</head>
100
<body>
101
<html:form action=
"
/
register
"
onsubmit=
"
return
sub()
"
>
102
<table>
103
<tr>
104
<td>
105
用户名
106
</td>
107
<td valign=
"
top
"
>
108
<html:text property=
"
name
"
onchange=
"
nameChange()
"
/>
109
</td>
110
<td valign=
"
top
"
>
111
<div id=
"
name1
"
>
112
<font size=
"
2
"
>*用户名在5-50位之间</font>
113
<div>
114
</td>
115
</tr>
116
<tr>
117
<td valign=
"
top
"
>
118
密码
119
</td>
120
<td valign=
"
top
"
>
121
<html:password property=
"
pwd
"
onchange=
"
pwdChange()
"
/>
122
</td>
123
<td valign=
"
top
"
>
124
<div id=
"
pwd1
"
>
125
<font size=
"
2
"
>*密码必须含有大写字母、小写字母、标点、数字中的至少两种。,长度在5-20之间</font>
126
</div>
127
</td>
128
</tr>
129
<tr>
130
<td valign=
"
top
"
>
131
确认密码
132
</td>
133
<td valign=
"
top
"
>
134
<html:password property=
"
rpwd
"
onchange=
"
rpwdChange()
"
/>
135
</td>
136
<td valign=
"
top
"
>
137
<div id=
"
rpwd1
"
>
138
<font size=
"
2
"
>*重复上面的密码<br> </font>
139
</div>
140
</td>
141
</tr>
142
<tr>
143
<td valign=
"
top
"
>
144
性别
145
</td>
146
<td valign=
"
top
"
>
147
<html:select property=
"
sex
"
>
148
<html:option value=
"
男
"
>男</html:option>
149
<html:option value=
"
女
"
>女</html:option>
150
</html:select>
151
</td>
152
<td valign=
"
top
"
></td>
153
</tr>
154
</table>
155
156
<html:submit value=
"
注册
"
/>
157
</html:form>
158
</body>
159
</html>
160
161
1
/**/
/*
2
* Generated by MyEclipse Struts
3
* Template path: templates/java/JavaClass.vtl
4
*/
5
package
xxn.web.action;
6
7
import
java.io.IOException;
8
import
java.io.PrintWriter;
9
10
import
javax.servlet.http.HttpServletRequest;
11
import
javax.servlet.http.HttpServletResponse;
12
13
import
org.apache.struts.action.Action;
14
import
org.apache.struts.action.ActionForm;
15
import
org.apache.struts.action.ActionForward;
16
import
org.apache.struts.action.ActionMapping;
17
18
import
xxn.dao.UserDao;
19
import
xxn.model.User;
20
import
xxn.web.form.RegisterForm;
21
22
/** */
/**
23
* MyEclipse Struts
24
* Creation date: 12-27-2007
25
*
26
* XDoclet definition:
27
* @struts.action path="/register" name="registerForm" input="/register.jsp" scope="request" validate="true"
28
*/
29
public
class
RegisterAction
extends
Action
{
30
/**/
/*
31
* Generated Methods
32
*/
33
34
/** */
/**
35
* Method execute
36
*
@param
mapping
37
*
@param
form
38
*
@param
request
39
*
@param
response
40
*
@return
ActionForward
41
*/
42
public
ActionForward execute(ActionMapping mapping, ActionForm form,
43
HttpServletRequest request, HttpServletResponse response)
{
44
RegisterForm registerForm
=
(RegisterForm) form;
//
TODO Auto-generated method stub
45
ActionForward af
=
new
ActionForward();
46
UserDao ud
=
new
UserDao();
47
if
(registerForm.getName()
==
null
)
{
48
af
=
mapping.getInputForward();
49
}
else
{
50
if
(
"
1
"
.equals(request.getParameter(
"
test
"
)))
{
51
//
验证用户名的代码。
52
try
{
53
PrintWriter out
=
response.getWriter();
54
//
在这里可以根据从数据库中查询的数据返回不同的值。1:用户存在,0:用户不存在
55
56
if
(ud.getUserByName(request.getParameter(
"
name
"
)))
{
57
out.print(
1
);
58
//
ajax取得都是字符的输出。如果数据量大的话,还可以用xml来发送和接受
59
}
else
{
60
out.print(
0
);
61
}
62
63
return
null
;
64
//
注意:这里必须return null 否则页面接收不到返回值。
65
66
}
catch
(IOException e)
{
67
//
TODO Auto-generated catch block
68
e.printStackTrace();
69
}
70
}
else
{
71
//
正常注册的代码。
72
User u
=
new
User();
73
u.setName(registerForm.getName());
74
u.setPassword(registerForm.getPwd());
75
u.setSex(registerForm.getSex());
76
ud.save(u);
77
78
}
79
80
}
81
return
af;
82
}
83
}
posted on 2007-12-27 18:34
徐先念
阅读(2691)
评论(9)
编辑
收藏
Feedback
#
re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
2008-03-12 11:44
d
sdfsdf
回复
更多评论
#
re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
2008-05-07 00:14
庄三笑
不错。谢谢分享
回复
更多评论
#
re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在[未登录]
2008-05-12 08:54
qq
很乱!
回复
更多评论
#
你好
2008-09-28 12:24
爱仕达
是个分公司
回复
更多评论
#
re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在[未登录]
2009-04-02 09:41
过客
我页面总是获得不了 out.print( 0 );
这个值 什么原因呢
回复
更多评论
#
re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
2009-04-17 23:52
dadaad
fsdf
回复
更多评论
#
re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
2009-07-14 10:04
问问
俄地方地方
回复
更多评论
#
re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在[未登录]
2012-02-24 15:02
啊
是 凤飞飞
回复
更多评论
#
re: JSP+Struts+ajax实现不刷新页面判断用户是否已经存在
2012-10-08 11:40
去
的撒旦
回复
更多评论
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
Powered by:
BlogJava
Copyright © 徐先念