1

I have an ajax request function (written in JavaScript) and Java Servlet that handles this request. I need to get all request parameters and if it succeeded then send back a confirmation that it has succeeded. How I can send a confirmation message? As an attribute, like {isSuccess: true}. My code:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
    IOException {
    Enumeration<?> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        // storing data fn
    }
    // how to send back a message here?
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Related: http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax/4113258#4113258 – BalusC Nov 15 '12 at 12:36

1 Answers1

1

Get PrintWriter object by calling HttpServletResponse#getWriter and write your String.

response.getWriter().write("{isSuccess: true}");
Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103