Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

flush and forward works ?

 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HFSJ says, if you do flush and forward, a exception will be thrown
but no one will see the exception.The client will see 'Hi all' as a response from the sample.jsp but he wont see anything as a response from
other.jsp.

-----code in sample.jsp-----
Hi all
<%out.flush();%>
<jsp:forward page="other.jsp"%>

now please see thins question -

Consider the source for the following two JSP pages, a.jsp and b.jsp. What is the outcome of requesting each in turn? You can assume that �c.jsp� is available in the same web application directory as a.jsp and b.jsp. (Choose two.)

Source for a.jsp:
<%@page buffer="none" autoFlush="true"%>
<jsp:forward page="c.jsp"/>
Source for b.jsp:
<%@page buffer="none" autoFlush="true"%><jsp:forward page="c.jsp"/>
A. Neither JSP page translates.
B. a.jsp translates; b.jsp does not.
C. b.jsp translates; a.jsp does not.
D. Both JSP pages translate.
E. Neither JSP page runs successfully.
F. a.jsp runs successfully; b.jsp does not.
G. b.jsp runs successfully, a.jsp does not.
H. Both a.jsp and b.jsp run successfully.

of course D is one of the options.
keeping in mind the thing said in HFSJ, i selected H as the second option.
but the another answer given is G.

what i want to say is -



is equiivalent to



so D and H are the correct answers.

ok ?
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niranjan,


is not equivalent to


It simply means that the JspWriter will have no buffering .Remember that it is a page directive and it does not translate to any code in service method.Its just a instruction to the compiler

Since nothing is written to response stream by both the jsps , forward to c.jsp will work fine.

HTH
[ November 14, 2006: Message edited by: Vivek Pandey ]
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since nothing is written to response stream by both the jsps , forward to c.jsp will work fine.

hmm... i too thought the same !
hope some other rancher find the problem in the code !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic