This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Included JSP cannot set headers?" Watch "Included JSP cannot set headers?" New topic
Author

Included JSP cannot set headers?

Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
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
SCEA
SCJWSD
SCJD
SCBCD
SCWCD
SCJP
CNA
Brasilia - BRASIL
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
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: http://aspose.com/file-tools
 
subject: Included JSP cannot set headers?
 
Similar Threads
JSTL c:redirect doesn't work from included jsp file
Setting a header
Use RequestDispatcher to include page content?
question about RequestDispatcher
changing status code