Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Vs Servlet - A peculiar scenario

 
Gaurav Kushwaha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a faced a scenario, wherein I am not able to know the reason for it.
While trying to display an html page (kept in my local directory), I have created 2 web projects. One with only a jsp and written file I/O code to get the file and writing in the ServletOutputStream. But it didn't work. It gave me IlleagalStateException, saying getOutputStream already called.

However, the other project wherein I had a servlet, with same code. It worked fine.

I am not understanding the reason.


Thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It gave me IlleagalStateException, saying getOutputStream already called.


Explains the reason - in a JSP, the output stream is automatically created by the code created by the JSP compiler so that you will have the automatic variable "out"

Examine the created servlet code to see all the work that JSP does automatically to set up out and other variables.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you putting Java code into your JSP?
 
Gaurav Kushwaha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Bear, I am maintaining a decade long code which was written in jsp
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My condolences!
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav Kushwaha wrote:I am maintaining a decade long code which was written in jsp

so, those all the day you were getting the exception?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic