AJAX交互Struts2问题? 在线等!!!
我在前台的代码是:
makeRequest("./action/login/loginmain.do?loginName="+loginName+"&json="+json,null,"onLogon");
makeRequest是 封装ajax的一个方法
/登录请求返回后调用
function onLogon(){
// 4:XMLHttpRequest对象读取服务器响应结束。
if (http_request.readyState == 4){
if (http_request.status == 200){
var State=window.http_request.responseText;
alert(State);
if(State =="true"){
alert("用户名称可以使用");
}else{
alert("用户名,密码不正确");
}
}else {
alert('登录失败, 请检查本地网络');}
}
后台action中代码:Struts2
private String State;//get.set方法。。
public String validateLogin() throws Exception
{
if(loginName.equals("admin"))
{
System.out.println("存在用户");
this.State="true";
return "main"
}else{
System.out.println("用户和密码不正确");
this.State="false";
return "login";
}
为什么我的State在前台alert(State)是一个页面啊,而不是我想要的true,false,怎么回事,我怎么样能得到State的值呢