virsir
virsir

Reputation: 15489

How to add a response header before forwarding to another resource

I hava a servlet which handles some resources files, and I need to add a response header before I forward the request to the real jsp file.

response.setHeader("a", "b");
request.getRequestDispatcher("1.jsp").forward(request, response);

I need to send that header directly to the browser, But it did not work, I tried to use firebug to watch the http request and its response, how can I do that?

Upvotes: 1

Views: 10509

Answers (4)

shapiy
shapiy

Reputation: 1155

The headers are being cleaned up. Just curious, what stops you from using request.setAttribute()?

Upvotes: 0

Igor Artamonov
Igor Artamonov

Reputation: 35961

Try to use .include(request, response) instead. Probably it's a .forward() feature to fully clean response object before forwarding.

See http://download.oracle.com/javaee/5/api/javax/servlet/RequestDispatcher.html

Upvotes: 1

YODA
YODA

Reputation: 309

If you want to use some data added by the servlet in the 1.jsp code, I suggest you use request.setAttribute method. response.addHeader/setHeader put some data into the response'header. Generally the data in the response header is used by the browser.

Upvotes: 0

Adeel Ansari
Adeel Ansari

Reputation: 39887

How do you know that it is not working? Please read this JR thread, I believe you are expecting similar thing.

Upvotes: 0

Related Questions