I want to add some plain text and two headers to the HttpServletResponse
, the code is the following:
resp.setContentType("text/plain");
resp.getWriter().write(messages.get(next).getContent());
resp.addHeader("success", "yes");
resp.addHeader("hasnext", ((Boolean)hasNext).toString());
The problem I encounter is that sending the content prevents the sending of the headers. If I don't write the content the headers are received fine, if I include the text they don't.
What is the problem ?
Try setting your headers first. Also I'm assuming you call writer.flush()
after you are done with your response.
UPDATE
Can you check if the following works:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader("Content-Type", "text/plain");
response.setHeader("success", "yes");
PrintWriter writer = response.getWriter();
writer.write("hello\n");
writer.close();
}
Use curl -i http://yourapp.appspot.com
to verify the headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With