This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Enthuware Simulator Question (SCWCD 5)  RSS feed

 
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Enthuware Test


Consider the following code snippets. What will be displayed on the browser when a GET request is sent to FirstServlet assuming that the buffer is large enough to hold all the data before sending the data to the client?


Select 1 correct option.
a.Only Page1 and Page3


b.Only Page2


c.Page1, Page2, and Page3


d.IllegalStateException at Runtime.
See general comments.

e.Compilation Error.


General Comments
The servlet specification mandates that when a request is "forwarded" to another resource, the buffer should be cleared of the contents generated by the forwarding resource. Therefore, only Page2 will be sent to the client. However, calling forward() means that the request processing is delegated to the callee resource permanently. So, although the control does return to the caller resource [because rd.forward() is just a regular method call], the caller resource cannot generate any output after the call to forward().
In this case, FirstServlet is trying to send output to the client after calling forward() and so an IllegalStateException will be thrown.



In the doGet() of FirstServlet:

In the doGet() of SecondServlet:


--------------------------------------------------------------------------------------------
I tired the same example:

doGet() of Source servlet


doGet() of Destination Servlet



As per the general comments ,I should get an Exception .
But,I am able to see
Destination in the Browser output when i ran Source Servlet and request is forwarded successfully.

Why such different behavior ?
 
Ranch Hand
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohit

1)You only get IllegalStateexception when the caller of forward() method has committed response which in case it has not.

2)Also after the forward() method returns any attempt to write to output will not be entertained and just ignored.

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so Ankur ,Only Page2 is the correct answer
 
Ankur Gargg
Ranch Hand
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes mohit.Whatever is written by forwarded resource will result in ultimate response.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!