I am using Servlet as controller and jquery to send request to server. Following is my jquery request
$.post("login", {userName:$userName, password:$password}, function(data, textStatus) {
alert(textStatus);
});
And in server side i have written following code
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println("" + strError + "");
out.flush();
out.close();
I want to set error message and error error status code in servlet and read the same status code in jquery. How can I achieve the same?
You can return a json encoded string from the server. How do you return a JSON object from a Java Servlet
For example if you sent the following json encoded string back.
{‘error’: ‘This is some error message’ }
Then on the client side you would do the following