Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to understand this HINT from SCWCD HINT.

 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
" Always remember that the included pages can't do anything to the headers. Be it a servlet or a jsp. "

But why ?? because i did tried one example and it is working fine . i included one jsp which is setting a new header and it is not giving me any problem.
Can someone explain me where i am getting wrong in understanding this statement.

Regards,
Sagar.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2337
87
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JSP 2.2 specs:

JSP.5.4 <jsp:include>
An included page cannot change the response status code or set headers. This
precludes invoking methods like setCookie. Attempts to invoke these methods
will be ignored


Regards,
Frits
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits.

Also one thing i will like to ask you is there anything specified in the specs which says that
"Even if you dont flush the response,you should not write anything in the response or set headers or cookies incase if you gonna do a forward"
Anything like this ? i know that you said earlier that for practical purposes you shouldnt do this but i want to what is specified regarding this matter in the specs,since the exam is all about what specs says

Regards,
Sagar.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2337
87
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if you dont flush the response,you should not write anything in the response or set headers or cookies incase if you gonna do a forward"
Anything like this ? i

This is written about it:

SRV.8.4 The Forward Method
The forward method of the RequestDispatcher interface may be called by the
calling servlet only when no output has been committed to the client. If output data
exists in the response buffer that has not been committed, the content must be
cleared before the target servlet's service method is called
. If the response has been
committed, an IllegalStateException must be thrown.
....
Before the forward method of the RequestDispatcher interface returns, the
response content must be sent and committed, and closed by the servlet container.

the phrase "the content must be cleared ..." is what the container should do. Everything that was written to the response (before the forward) is therefore lost.

Regards,
Frits
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Frits !

Regards,
Sagar

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic