• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalStateException

 
Claudia Vaz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't really an EJB issue so I am sending this to the JSP forum.
 
Claudia Vaz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out should write to the browser's console.
------------------
Bosun
SCJP for the Java� 2 Platform
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic