-
关注
-
a454569399
-
a454569399
-
本版等级:
-
结帖率:100%
-
|
楼主
发表于: 2011-11-26 14:40:23
本人新手,学习extjs3.0,要把它整合到struts2.1+spring2.5+hibernate3.0的框架中去,想做个添加管理员的功能,可是每次都是调用failure函数还提示错误类型connect,相关代码如下,请各位解答!(本人已经测试过了,如是用jsp做表现层,能把数据写入到数据库而用extjs做表现层则不行)
struts.xml的配置文件如下(action的配置)
1
2
3
4
5
6
7
8
9
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<
struts
>
<
package
name
=
"json"
namespace
=
"/"
extends
=
"json-default"
>
<
action
name
=
"addUser"
class
=
"addUser"
method
=
"add"
>
<
result
type
=
"json"
/>
</
action
>
</
package
>
</
struts
>
|
addUser.action的代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package
per.ssh.action.admin;
import
java.io.IOException;
import
com.opensymphony.xwork2.ActionSupport;
import
per.ssh.dao.Admin.Admin;
import
per.ssh.services.admin.adminInterface;
public
class
adminAction
extends
ActionSupport{
private
boolean
success;
private
String msg=
""
;
/**
* @return the success
*/
public
boolean
isSuccess() {
return
success;
}
/**
* @param success the success to set
*/
public
void
setSuccess(
boolean
success) {
this
.success = success;
}
/**
* @return the msg
*/
public
String getMsg() {
return
msg;
}
/**
* @param msg the msg to set
*/
public
void
setMsg(String msg) {
this
.msg = msg;
}
private
User user;
public
User getUser(){
return
this
.user;
}
public
void
setUser(User user){
this
.user=user;
}
private
adminInterface testService=
null
;
public
void
setTestService(adminInterface testService){
this
.testService=testService;
}
public
String add()
throws
IOException{
Admin admin=
new
Admin(user.getUserName(),user.getPassword(),Integer.parseInt(user.getUserLevel()));
try
{
testService.insert(admin);
success=
true
;
msg=
"添加管理员成功!"
;
}
catch
(Exception ex){
success=
false
;
msg=
"用户名或密码错误!"
;
}
System.out.println(user.getUserName()+user.getPassword()+user.getUserLevel());
return
SUCCESS;
}
}
|
extjs的代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
Ext.ns(
"per.extjs.userManager"
);
Ext.apply(Ext.form.VTypes,{
confrimPwd:
function
(val,field){
if
(field.initalPassword){
var
pwd=Ext.getCmp(field.initalPassword);
return
(val==pwd.getValue());
}
return
true
;
},
confrimPwdText:
'两次密码输入不一致!'
});
per.extjs.userManager.userForm=
function
(){
var
boxStore=
new
Ext.data.SimpleStore({
fields:[
'user'
,
'level'
],
data:[[
'超级管理员'
,
'1'
],[
'一般管理员'
,
'2'
]]
});
var
userLevel=
new
Ext.form.ComboBox({
id:
'userLevel'
,
name:
'user.userLevel'
,
fieldLabel:
'用户类别'
,
forceSelection:
true
,
triggerAction:
'all'
,
editable:
false
,
labelWidth:100,
width:125,
store:boxStore,
displayField:
'user'
,
valueField:
'level'
,
mode:
'local'
,
value:
'1'
,
width:600
});
var
userName=
new
Ext.form.TextField({
id:
'userName'
,
name:
'user.userName'
,
fieldLabel:
'用 户 名'
,
allowBlank:
false
,
blankText:
'用户名不能为空!'
,
msgTarget:
'under'
,
width:600
});
var
password=
new
Ext.form.TextField({
id:
'password'
,
name:
'user.password'
,
fieldLabel:
'用户密码'
,
allowBlank:
false
,
blankText:
'密码不能为空'
,
inputType:
'password'
,
msgTarget:
'under'
,
width:600
});
var
confrimPassword=
new
Ext.form.TextField({
id:
'cpwd'
,
name:
'cpwd'
,
fieldLabel:
'重复密码'
,
inputType:
'password'
,
initalPassword:
'password'
,
vtype:
'confrimPwd'
,
allowBlank:
false
,
blankText:
'重复密码不能为空'
,
msgTarget:
'under'
,
width:600
});
per.extjs.userManager.userForm.superclass.constructor.call(
this
,{
id:
'userForm'
,
title:
'添加管理员'
,
frame:
true
,
autoHeight:
true
,
applyTo:
'main'
,
labelAlign:
'right'
,
buttonAlign:
'center'
,
labelWidth:
'100'
,
width:760,
collapsible:
true
,
animCollapse:
true
,
bodyStyle:
'padding:5px;'
,
items:[
{
xtype:
'fieldset'
,
title:
'管理员信息'
,
autoHeight:
true
,
autoWidth:
true
,
items:[userLevel,userName,password,confrimPassword]
}
],
buttons:[
{
text:
'提交'
,
handler:submit
},{
text:
'取消'
,
handler:reset
}
]
});
function
submit(){
Ext.getCmp(
'userForm'
).form.submit({
clientValidation:
true
,
url:
'addUser.action'
,
method:
'POST'
,
success:
function
(form,action){
Ext.Msg.alert(
'提示'
,
"添加管理员成功!"
);
},
failure:
function
(form,action){
Ext.Msg.alert(
'提示'
,action.failureType+
":"
+action.getUrl());
}
});
}
function
reset(){
Ext.getCmp(
'userForm'
).form.reset();
}
}
Ext.extend(per.extjs.userManager.userForm,Ext.form.FormPanel,{});
|
相应的jsp页面代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<%@ page language='java' import='java.util.*' pageEncoding='GBK'%>
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<
html
>
<
head
>
<
base
>
<
link
rel
=
"stylesheet"
type
=
"text/css"
href
=
"${pageContext.request.contextPath}/extjs/resources/css/ext-all.css"
/>
<
script
type
=
"text/javascript"
src
=
"${pageContext.request.contextPath}/extjs/adapter/ext/ext-base.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"${pageContext.request.contextPath}/extjs/ext-all-debug.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"${pageContext.request.contextPath}/pages/common/common.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"${pageContext.request.contextPath}/pages/userManager/userManager.js"
></
script
>
<
title
>My JSP "test.jsp" starting page</
title
>
<
meta
http-equiv
=
"pragma"
content
=
"no-cache"
>
<
meta
http-equiv
=
"cache-control"
content
=
"no-cache"
>
<
meta
http-equiv
=
"expires"
content
=
"0"
>
<
meta
http-equiv
=
"keywords"
content
=
"keyword1,keyword2,keyword3"
>
<
meta
http-equiv
=
"description"
content
=
"This is my page"
>
<
script
type
=
"text/javascript"
>
Ext.onReady(function(){
Ext.BLANK_IMAGE_URL="${pageContext.request.contextPath}/extjs/resources/images/default/s.gif",
Ext.QuickTips.init();
var top=new per.extjs.common.top();
var nav=new per.extjs.common.nav();
var foot=new per.extjs.common.foot();
var form=new per.extjs.userManager.userForm();
});
</
script
>
</
head
>
<
body
>
<
table
width
=
"960"
align
=
"center"
>
<
tr
>
<
td
id
=
"head"
colspan
=
"2"
></
td
>
</
tr
>
<
tr
>
<
td
id
=
"nav"
width
=
"200"
></
td
>
<
td
id
=
"main"
style
=
"vertical-align:top"
></
td
>
</
tr
>
<
tr
>
<
td
id
=
"foot"
colspan
=
"2"
></
td
>
</
tr
>
</
table
>
</
body
>
</
html
>
|
页面效果如下图所示:
点击提交按钮则出现如下错误提示:
请各位大虾给予解答!
width="728" height="90" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_1" name="aswift_1" style="box-sizing: content-box; left: 0px; position: absolute; top: 0px;">
-
id="iframeu1636200_0" src="http://pos.baidu.com/ncam?rdid=1636200&dc=2&di=u1636200&dri=0&dis=0&dai=2&ps=5598x225&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1467855802926&ti=Extjs3.0%E6%95%B4%E5%90%88ssh%E6%97%B6%E6%8F%90%E4%BA%A4%E8%A1%A8%E5%8D%95%EF%BC%8C%E6%80%BB%E6%98%AF%E6%89%A7%E8%A1%8Cfailure%E5%87%BD%E6%95%B0%EF%BC%8C%E4%B8%8D%E7%9F%A5%E9%81%93%E4%B8%BA%E4%BB%80%E4%B9%88%2C%E8%AF%B7%E5%90%84%E4%BD%8D%E5%A4%A7%E8%99%BE%E6%8C%87%E6%95%99%EF%BC%81-CSDN%E8%AE%BA%E5%9D%9B-CSDN&ari=1&dbv=2&drs=3&pcs=1029x720&pss=1029x8874&cfv=0&cpl=4&chi=1&cce=true&cec=UTF-8&tlm=1467855802&rw=720<u=http%3A%2F%2Fbbs.csdn.net%2Ftopics%2F380071240<r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DzLgDqhfz8nxGjwu4vv1EG3GrBW1_g6QH6uGk1exBftqgBtsRaMt6j6pRuujshqVW%26wd%3D%26eqid%3Dedc75c0a0003cc2000000005577db2e1&ecd=1&psr=1920x1080&par=1920x1040&pis=-1x-1&ccd=24&cja=false&cmi=6&col=zh-CN&cdo=-1&tcn=1467855803&qn=671535a9eb8afac9&tt=1467855802906.24.201.202" width="200" height="22" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="box-sizing: content-box; border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;">
-
id="iframeu1636201_0" src="http://pos.baidu.com/ncam?rdid=1636201&dc=2&di=u1636201&dri=0&dis=0&dai=3&ps=5598x479&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1467855802926&ti=Extjs3.0%E6%95%B4%E5%90%88ssh%E6%97%B6%E6%8F%90%E4%BA%A4%E8%A1%A8%E5%8D%95%EF%BC%8C%E6%80%BB%E6%98%AF%E6%89%A7%E8%A1%8Cfailure%E5%87%BD%E6%95%B0%EF%BC%8C%E4%B8%8D%E7%9F%A5%E9%81%93%E4%B8%BA%E4%BB%80%E4%B9%88%2C%E8%AF%B7%E5%90%84%E4%BD%8D%E5%A4%A7%E8%99%BE%E6%8C%87%E6%95%99%EF%BC%81-CSDN%E8%AE%BA%E5%9D%9B-CSDN&ari=1&dbv=2&drs=3&pcs=1029x720&pss=1029x8874&cfv=0&cpl=4&chi=1&cce=true&cec=UTF-8&tlm=1467855802&rw=720<u=http%3A%2F%2Fbbs.csdn.net%2Ftopics%2F380071240<r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DzLgDqhfz8nxGjwu4vv1EG3GrBW1_g6QH6uGk1exBftqgBtsRaMt6j6pRuujshqVW%26wd%3D%26eqid%3Dedc75c0a0003cc2000000005577db2e1&ecd=1&psr=1920x1080&par=1920x1040&pis=-1x-1&ccd=24&cja=false&cmi=6&col=zh-CN&cdo=-1&tcn=1467855803&qn=b1bf0d6ac849a7e2&tt=1467855802906.26.274.275" width="200" height="22" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="box-sizing: content-box; border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;">
-
id="iframeu1636204_0" src="http://pos.baidu.com/ncam?rdid=1636204&dc=2&di=u1636204&dri=0&dis=0&dai=4&ps=5598x733&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1467855802926&ti=Extjs3.0%E6%95%B4%E5%90%88ssh%E6%97%B6%E6%8F%90%E4%BA%A4%E8%A1%A8%E5%8D%95%EF%BC%8C%E6%80%BB%E6%98%AF%E6%89%A7%E8%A1%8Cfailure%E5%87%BD%E6%95%B0%EF%BC%8C%E4%B8%8D%E7%9F%A5%E9%81%93%E4%B8%BA%E4%BB%80%E4%B9%88%2C%E8%AF%B7%E5%90%84%E4%BD%8D%E5%A4%A7%E8%99%BE%E6%8C%87%E6%95%99%EF%BC%81-CSDN%E8%AE%BA%E5%9D%9B-CSDN&ari=1&dbv=2&drs=3&pcs=1029x720&pss=1029x8874&cfv=0&cpl=4&chi=1&cce=true&cec=UTF-8&tlm=1467855802&rw=720<u=http%3A%2F%2Fbbs.csdn.net%2Ftopics%2F380071240<r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DzLgDqhfz8nxGjwu4vv1EG3GrBW1_g6QH6uGk1exBftqgBtsRaMt6j6pRuujshqVW%26wd%3D%26eqid%3Dedc75c0a0003cc2000000005577db2e1&ecd=1&psr=1920x1080&par=1920x1040&pis=-1x-1&ccd=24&cja=false&cmi=6&col=zh-CN&cdo=-1&tcn=1467855803&qn=fc36d5d15b9b378d&tt=1467855802906.26.288.290" width="200" height="22" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="box-sizing: content-box; border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;">
|