0

I am a bit new to web programming..so. I am writing user register for an app. On server side I use Java, Tomcat and servlet, and on the client side jQuery. I want to check if the user I am registering exist and if so, I want to response with the text of my thrown exception. I've written the request like:

"$.ajax({

                url: url,
                method: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify(regUser),
                success: function(response) {
                    localStorage.setItem(LOCAL_STORAGE_AUTHKEY_KEY, response.authKey);
                    localStorage.setItem(LOCAL_STORAGE_USERNAME_KEY, response.username);
                    resolve(response);
                },
                error: function(error) {
                    console.log(error);
                    toastr.error(error);
                }

            });"

and the response, when I enter repeating user like:

catch (Exception e) {

String errorMessage = e.getMessage();

                System.out.println(errorMessage);
                response.setStatus(400);
                response.getWriter().write(errorMessage);
Ivaylo Pankov
  • 99
  • 1
  • 5
  • What exactly is your question? Is there something in the code that doesn't work, or are you asking how to perform a "user exists" check that the posted code will rely upon? And welcome to StackOverflow! – plamut Nov 30 '15 at 20:46
  • 10x. My question is how to return the message, which I've trhown on server to client. Ex. when I throw IllegalArgumentException, with text "some text", how to get "some text" on client side with jQuery error function – Ivaylo Pankov Dec 01 '15 at 07:17

0 Answers0