• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

include to an html file throws an exception  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
   I am new to Servlets and JSPs.
   I just discovered that the include method on the requestDispatcher can be invoked for a static HTML page.
My question is , how does the control flow back to the calling servlet or jsp after the include method execution . Also , when I tried running the below code, it gave me an IllegalStateException(), getOutputStream() has already been called for this response:



I dont knw what the issue is!
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this line: you want to print the "back here" to the respone. But in previous line: you have already set the response object to return, so the error will throw. Let's make sure that you set any things to the response before pass it into the `include` function.
So the code should be:

       
 
Swarna Gururaja
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks , your solution does solve the issue with html pages.
When I replace the Html page with a JSP though , it does not throw the exception, and works perfectly. Is there a difference?

 
 
Swarna Gururaja
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding to my previous reply , even this works :

              

Obtaining the writer before dispatching the request and response object to another resource works.

Also, can someone explain the meaning of this statement:
If the resource is static, the include method enables programmatic server-side includes. If the resource is a web component, the effect of the method is to send the request to the included web component, execute the web component, and then include the result of the execution in the response from the containing servlet. An included web component has access to the request object but is limited in what it can do with the response object.

I am missing some basic understanding here about request dispatching.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!