Login in Extjs using java spring Bean

168 views Asked by At

I am trying to authenticate a user's username and password using an Ajax call.The parameters are passed to java bean and it should return a success or a failure message string to the caller but it shows a Servlet service error.The code is as follows:

  package com.eits.portal.controller;
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import net.sf.json.JSONObject;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

  import com.eits.portal.service.OrgTreeService;


public class UserLoginController  extends MultiActionController {
OrgTreeService orgTreeService;

ModelAndView mv;
public String getLoginStatus(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
        throws Exception{
    //paramHttpServletResponse.setContentType("application/json");

    String userId = paramHttpServletRequest.getParameter("user");
    String password = paramHttpServletRequest.getParameter("password");
    String s="";
      System.out.println("---node"+userId);
      System.out.println("---node"+password);
      String us="admin";
      String pass="admin";



      if(userId.equals(us)&& password.equals(pass)){
                 s="success";
          System.out.println("success ");
      }else{
          s="failure";

          System.out.println("unsuccessful");
      }

      return s;
}
 public void setOrgTreeService(OrgTreeService paramOrgTreeService)
  {
     this.orgTreeService = paramOrgTreeService;
  }

 }

The code is pretty simple and it does print success on passing the right username and password in the IDE console , but the same string is not passing to the caller function for the front end.Here is a snapshot of the error I am getting :-

  http://gyazo.com/12b386a9e586fc0ee5514800c9822071

Is this a right way to pass the success to the caller method , or should i pass an object instead of the string?

1

There are 1 answers

1
midrig On

Firstly, if you are getting a 404 (Not Found) then you should check that you are calling the correct URL and that your servlet request mapping configuration is specified correctly, e.g. via @RequestMapping annotation if using Spring.

Then, assuming you are making a request similar to below, you can return a Json string from your controller method that will be returned in the response and can be decoded into an object, assuming you may want to pass back more details than simply "success" or "failure".

Ext.Ajax.request({
  url: '/someUrl',
  params: {
    user: 'username',
    password: 'password'
  },
  callback: function(options, success, response) {
    if (success) {
      var obj = Ext.decode(response.responseText);
      ....
    }
  }
});