File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes JSP Vs Servlet - A peculiar scenario Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "JSP Vs Servlet - A peculiar scenario" Watch "JSP Vs Servlet - A peculiar scenario" New topic
Author

JSP Vs Servlet - A peculiar scenario

Gaurav Kushwaha
Greenhorn

Joined: May 20, 2009
Posts: 19
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

Joined: Mar 22, 2000
Posts: 11863
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

Java Resources at www.wbrogden.com
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

Are you putting Java code into your JSP?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Gaurav Kushwaha
Greenhorn

Joined: May 20, 2009
Posts: 19
No Bear, I am maintaining a decade long code which was written in jsp
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

My condolences!
Seetharaman Venkatasamy
Bartender

Joined: Jan 28, 2008
Posts: 4503

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?
 
 
subject: JSP Vs Servlet - A peculiar scenario
 
Threads others viewed
Hitting a JSP from a Servlet
unable to send huge data from jsp to servlet using doPost
Dynamic path name for FileAppender
File size check
environment variable
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com