user2365199
user2365199

Reputation: 29

How to add multiple headers to HttpServletResponse

I have been trying to do a very simple thing - to send multiple objects using HttpServletResponse response object.For that i am setting multiple objects in response object using setHeader method

response.setHeader("instanceDetails",new String(jsonBytes));
response.addHeader("nextStageList",new String(jsonBytes));

After adding multiple headers to HttpServletResponse response object in response i am getting "Reload the page to get source for" in firebug.
However if i send any one header field it is working fine.

        response.setHeader("instanceDetails",new String(jsonBytes));

I do not understand why setting multiple headers not working and sending one header is working ?

Upvotes: 0

Views: 2934

Answers (1)

DaniEll
DaniEll

Reputation: 1040

Headers are not supposed to contain arbitrary data. Send your data in the HTTP Response Entity Body.

You may send data in the entity body like this:

OutputStream out = response.getOutputStream();
out.write(jsonBytes);

Upvotes: 1

Related Questions