81,092
社区成员
发帖
与我相关
我的任务
分享
public String loginOn() throws IOException{
String resultStr = SUCCESS;
HttpServletResponse response = ServletActionContext.getResponse();
response.getWriter().print("{success:true,msg:'登录成功!'}");
return resultStr;
}
[code]
这是我action中这样写的。。
[code=JScript]login : function() {
if (this.fp.form.isValid()) {
this.fp.form.submit({
waitTitle : '请稍候',
waitMsg : '正在登录......',
url : 'user/loginOn.action',
success : function(form, action) {
Ext.Msg.alert('提示', action.result.msg);
},
failure : function(form, action) {
form.reset();
Ext.Msg.alert('警告', action.result.msg);
}
});
}
}
这是js中写的。。
//action
public String query(){
try{
json=this.getUserService().queryUsers();
outJsonString(json);
success=true;
return null; //注意返回是null
}catch(Exception e){
e.printStackTrace();
return "error";
}
}
//service
public String queryUsers(){
System.out.println("struts2 userService");
List<User> list=this.getUserDao().queryUsers();
//String str = this.getJsonarray().fromObject(list).toString();
//String json = "{\"totalProperty\":"+list.size()+",\"success\":true,\"root\":"+str+"}";
// System.out.println(json);
String str="[{\"userno\":\"1\",\"userpassword\":\"q123456\",\"username\":\"li\"}]";
String json = "{totalProperty:1,root:"+str+"}";
return json;
//\"success\":true,
}
<struts> <constant name="objectFactory" value="spring"></constant> <include file="struts-default.xml" /> <package name="json" extends="json-default"> <action name="user" class="com.test.UserAction"> <result type="json"> </result> </action> </package> </struts>