how to get json response in jsp

I am making an ajax POST request in my project which will check the database value and returns me some response.When i make a request it does not returns me the text that i written.Am i missing something ?
My expected result should be success if it matches the condition or else Hello.
Thanks in advance !
My Script

 var mydata = $("#form").serialize()+"&" + $.param(data);
          type: "POST",
          url: "loginCheck.jsp",
          dataType : "json",
          data: mydata,
          error:function (res){ 
          success: function(response){
               console.log("response", response);

My loginCheck.jsp

  <%@page import=""%>
  <%@page import="com.admin.DBConnec"%>
     Gson gson = new Gson();
     String username = request.getParameter("uname").trim();
     String password= request.getParameter("upass").trim();
          DBConnec db =new DBConnec();
          db.stmt=db.con.prepareStatement("SELECT username, AES_DECRYPT(userpass, 'sumn2u') from user where username='"+username+"'");

      String user=(db.Rs.getString(1));
      String pass=(db.Rs.getString(2));
       session.setAttribute("username", user);

       if(user.equals(username) && pass.equals(password)){

        }else {    

       }catch (Exception ex){
           System.out.println("Exception Occured : "+ ex);


And what i got in my console is
enter image description here

Its adding the spaces what would i have to do to remove space so that i could get success only or may be in JSON format.
enter image description here

Source: jsp

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.