1

我有一个 ajax 请求函数(用 JavaScript 编写)和处理这个请求的 Java Servlet。我需要获取所有请求参数,如果成功,则发回确认成功。如何发送确认消息?作为一个属性,如{isSuccess: true}. 我的代码:

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

1 回答 1

1

PrintWriter通过调用HttpServletResponse#getWriter并编写您的String.

response.getWriter().write("{isSuccess: true}");
于 2012-11-13T18:25:21.313 回答