This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes IllegalStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "IllegalStateException" Watch "IllegalStateException" New topic
Author

IllegalStateException

Claudia Vaz
Ranch Hand

Joined: Nov 13, 2001
Posts: 44
Hello,
I am downloading a file from the server and saving it to the client disk.
I am using a jsp file that cles a Java function.
He makes it but gives the following error:
"2001-12-13 08:44:27 - Ctx( /PS2 ): IllegalStateException in: R( /PS2 + /save.jsp
+ null) OutputStream is already being used for this request"

In the Java API, IllegalStateException is a Runtime Excepttion, so i think the problem is in Java. However i don't understand.
I closed the outputstream and also flushed it.

Can you help me? I really don't know was is wrong!!!

Thanks
Claudia
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Can you explain how you are trying to write to the client disk from a JSP? Are you trying to send something back through the "out" variable? Why not show a little code?


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
This isn't really an EJB issue so I am sending this to the JSP forum.
Claudia Vaz
Ranch Hand

Joined: Nov 13, 2001
Posts: 44
Hello
Here is the code.
In a jsp file i call a java method:
"<jsp:useBean id="downloadSave" scope="page" class="DownloadSave" />
<%
String nameFichEur = request.getParameter("nomeFile");
downloadSave.doSave(nameFichEur,response);
%>"
The code of the class downloadSave is:
"import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class DownloadSave
{
public void doSave(String nameFichEur, HttpServletResponse res)throws ServletException, IOException
{

String pathFichEur = "c:\\jakarta-tomcat-3.2.3\\webapps\\PS2\\WEB-INF\\classes\\uploaddir\\" + nameFichEur;
System.out.println("nameFichEur: " + nameFichEur);
System.out.println("pathFichEur: " + pathFichEur);
//res.setContentType("application/x-filler");
res.setContentType("application/txt");
res.setHeader("Content-Disposition","attachment;filename=" + nameFichEur );

try
{
FileInputStream fileInput = new FileInputStream(pathFichEur);
int numOfBytes = fileInput.available();
byte byteArray[] = new byte[numOfBytes];
int nextByte = fileInput.read(byteArray);
fileInput.close();

OutputStream outStrm = res.getOutputStream();
outStrm.write(byteArray);
//outStrm.flush();
outStrm.close();
}
catch(IOException ioe)
{
System.out.println("download:file input exception");//..........
//ioe.printStackTrace();
}
catch(Exception e)
{
System.out.println("download: exception");//..........
}
}
}"
I hope you can help me!!!
Thanks
Claudia Vaz
Claudia Vaz
Ranch Hand

Joined: Nov 13, 2001
Posts: 44
Hello again
I forgot. I am using Tomcat.
Also, in tha Java class i tried to cath the exception using the following code:
"catch(IllegalStateException ise)
{
System.out.println("illegalstateexception: " + ise.getMessage());
ise.printStackTrace();
}"
and in Tomcat window the system.out.println doesn't appear.
Thanks
Claudia
Claudia
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
System.out should write to the browser's console.
------------------
Bosun
SCJP for the Java� 2 Platform


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
 
subject: IllegalStateException
 
Similar Threads
IllegalStateException
IllegalStateException
Outputstream, IllegalStateException
send file to the client/ jspsmart
exclusive file access