File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Included JSP cannot set headers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Included JSP cannot set headers?" Watch "Included JSP cannot set headers?" New topic

Included JSP cannot set headers?

Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1066
HF Servlets & JSP, page: 405 (first paragraph after the slide on the left side)It says....
There are a few limitations, though:an included page CANNOT change the response status code or set headers(which means it can't call, say, addCookies()). You won't get an error if the included JSP tries to do things it can't - you just won't get what you asked for.

Can somebody explain why I cannot change the response status or set headers in the included JSP?
Rodrigo Dinis
Ranch Hand

Joined: May 28, 2003
Posts: 40
Hi Vishwa,
you cannot do that because the servlet/jsp that include another page will override what you make on the header with its header. Trully talking you can do this, but it will not work.

Rodrigo Dinis
Brasilia - BRASIL
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1066
You may be right. If the including JSP overrides the headers before it sends the response to the client, it may not be possible.

But isn't that a restriction? . Not sure if the below makes any sense in practial projects.

Say Including JSP parent.jsp adds a cookie (cookie1) and then includes another JSP(child.jsp) at run time. This JSP(child.jsp) adds another cookie (cookie2) and returns.

Now the parent.jsp adds 1 more cookie (cookie3) and sends the response to the client.

Since it is the same response Object that is being shared by both the parent.jsp and child.jsp, why doesn't the client see all the 3 cookies?
I agree. Here's the link:
subject: Included JSP cannot set headers?
It's not a secret anymore!