user721588
user721588

Reputation:

handle ajax request and send response java servlet

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?
}

Upvotes: 1

Views: 8017

Answers (1)

Subhrajyoti Majumder
Subhrajyoti Majumder

Reputation: 41230

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

response.getWriter().write("{isSuccess: true}");

Upvotes: 1

Related Questions