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);
     $.ajax({
          type: "POST",
          url: "loginCheck.jsp",
          dataType : "json",
          data: mydata,
          error:function (res){ 
               console.log(res);
                            },
          success: function(response){
               console.log("response", response);
                            }
           });

My loginCheck.jsp

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

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

       if(user.equals(username) && pass.equals(password)){
            out.println("success");

        }else {    
            response.getWriter().write(gson.toJson("Hello"));
        } 
        }

       }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