Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Included JSP cannot set headers?

 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic