I have a servlet which accepts my ajax request which passes username and password as params from my LoginView in my ExtJs project .Here is the code for the same :
public class UserLoginController extends MultiActionController {
OrgTreeService orgTreeService;
ModelAndView mv;
public String getLoginStatus(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
throws Exception{
String str1 = paramHttpServletRequest.getParameter("user");
String str2 = paramHttpServletRequest.getParameter("password");
String s="";
System.out.println("---node"+str1);
System.out.println("---node"+str2);
if(str1.equals("admin") && str2.equals("admin")){
s="success";
}else{
s="failure";
}
return s;
}
and this is how I am making the ajax request from my View:
doLoginClicked : function() {
console.log("button pressed this time");
var name = this.view.getUsername();
var pass = this.view.getPassword();
console.log(name);
console.log(pass);
Ext.Ajax.request({
url: 'login/getLoginStatus.action',
method:'post',
params: {
user: name,
password: pass
}
,
success: function(response) {
console.log(response);
if (response=="success") {
// login.close();
} else {
console.log("inside failure");
Ext.Msg.show({
title:'Fail!',
msg: response,
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.OK
});
}
},
failure: function(response) {
console.log("inside failure");
Ext.Msg.show({
title:'Error!',
msg: response,
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.OK
});
}
});
}
It does show the username and password in the console from the servlet,But I am not able to accept the "success" response from the servlet and act accordingly.Here is the response that is being shown in the browser console :
Object {request: Object, requestId: 1, status: 200, statusText: "OK", responseText: ""…}getAllResponseHeaders: () {arguments: nullcaller: nulllength: 0name: ""prototype: response.getAllResponseHeadersconstructor: () {arguments: nullcaller: nulllength: 0name: ""prototype: response.getAllResponseHeaders__proto__: Empty() {}<function scope>__proto__: Object__proto__: Empty() {}<function scope>getResponseHeader: (header) {request: Objectasync: truebinary: falseheaders: Objectid: 1options: Object__proto__: ObjectrequestId: 1responseText: ""responseXML: nullstatus: 200statusText: "OK"__proto__: Object
Is there a way so that I could display the the home page when "Success" is returned from the servlet?
success: function(response)
the response
in the above line of code is an object. You will have to go a little deeper into your object, for eg, response.status == '200'
or response.responseText == "success"
.
As you have not given the exact response that you are getting, I will not be able to provide the exact code, but this is what the problem look to be.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.