• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing to jsp response

 
Shridhar Raghavan
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





The first snippet is the jsp code. I basically want to display both the html content and send across an excel representation of the html content. The second code basically generates an excel and writes that excel to the response. Now how do i accomplish sending across both html and excel. I am presently getting a "getWriter() has already been called" ie IllegalStateException error. The control comes to the JSP after a forward from a servlet. The third code snippet is the forwarding.
 
Tim Moores
Saloon Keeper
Posts: 3261
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't; it's either HTML or something else. Note that JSPs are not for creating binary content, so you have to send that Excel document some other way anyway, like stream it from within a servlet.
 
Shridhar Raghavan
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the servlet, can i send back both the html and the excel binary at the same time?
 
Tim Moores
Saloon Keeper
Posts: 3261
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No
 
Shridhar Raghavan
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

So any suggestions of what i could do? I would want to write both HTML and binary output back to the user. Preferably not design another action for getting the excel.
 
Tim Moores
Saloon Keeper
Posts: 3261
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. Period.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back up and tell us what you actually want to achieve. As Tim has pointed out, you can;t send two responses to one request.

And, you are putting Java code into a JSP in 2012? That's a horrible practice that has been discredited for 10 years now. 10 years! Time to update your JSP knowledge with the JSTL and EL.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!