• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Include() Doubt

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came acrss follwing question in the mock...

Will this not throw IllegalStateException...

The answer to this question is - C

Given the following code snippet, what would be the output you can expect to see on the web page? Mark

Please select one correct answer.



// Calling servlet:

public void doGet(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><BODY>");
out.println("I am calling others!");
RequestDispatcher rd= req.getRequestDispatcher("/MyServlet");
rd.include(req, res);
out.println("</BODY></HTML>");
out.close();
}

// Target servlet:

protected void doGet(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException
{
PrintWriter out = res.getWriter();
out.println("I am called by others!");
}

A : "I am calling others!".
B : "I am called by others!".
C : Both "I am calling others!" and "I am called by others!".
D : An IllegalStateException is thrown.
E : An IOException is thrown.
 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rd.include(req,res) is similar to jsp:include (which does not need to reset existing buffer) and not jsp:forward. So why should it throw any kind of exception?.

Even if you do res.flush() and then call rd.include(req,res) even then no exception is raised.Had this been the forward() method here, then the IllegalStateException would have occurred.
[ September 03, 2006: Message edited by: Shivani Chandna ]
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic