后台:
String userName = request.getParameter("userName");
String password = request.getParameter("password");
PrintWriter writer = response.getWriter();
response.setCharacterEncoding("UTF-8");
if("123".equals(userName)&&"123".equals(password)){
writer.write("success:true,message:'successInfo'}");
}else{
writer.write("success:false,message:'failureInfo'}");
}
//String message=request.getParameter("message");
System.out.println("userName"+userName);
System.out.println("password"+password);
System.out.println("message"+message);
writer.close();
前台EXT:
buttons:[{
text:"提交",
handler:function(){
var basic=this.up("form").getForm();
var userName= basic.findField("userName")
var password= basic.findField("password")
basic.submit({
params:[{userName:userName},
{password:password}
],
url:'/Test/login.do?method=login',
method:'POST',
success:function(form,action){
  //document.location="index.jsp";
Ext.Msg.alert("提示","成功:"+action.result.message);
},
failure:function(form,action){
Ext.Msg.alert("提示","失败"+action.result.message);
}
});
}
}]
现在这的问题是火狐会报:Ext.Error: You're trying to decode an invalid JSON String: success:true,message:'successInfo'}
问题1:我应该怎么办才能让成功的时候执行成功的提示,失败的时候执行失败的提示呢?
问题2:这个是一个很简单的登录,如果我想让成功的时候跳转页面,不知道是在前台document.location 跳转,还是在后台跳转呢?
我是新手,还请大家多多帮助,尽可能的说的详细点,多谢大家了!!!ExtJS登录 JSON函数URL

解决方案 »

  1.   

    1,json格式不正确,少了{
    if("123".equals(userName)&&"123".equals(password)){
    writer.write("{success:true,message:'successInfo'}");
    }else{
    writer.write("{success:false,message:'failureInfo'}");
    }2,在前台跳转,后台跳转没用
    success:function(form,action){
      document.location="index.jsp";
    }
      

  2.   

    多谢,前台跳转的document.location="index.jsp";这个函数,只能在该文件的文件夹内找吗?要是我想跳到别的页面例如webroot下的index.jsp的话,该如何写呢?
      

  3.   

    可以把url地址写上http://localhost:8888/工程名/webroot下的index.jsp
      

  4.   

    url:"../webroot/index.jsp"  从这个绝对路径跳到你要转的路径是没有问题的。。