File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes send file to the client/ jspsmart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "send file to the client/ jspsmart" Watch "send file to the client/ jspsmart" New topic

send file to the client/ jspsmart

Claudia Vaz
Ranch Hand

Joined: Nov 13, 2001
Posts: 44
I send a file to the server using the MultpartUpload of O'reilly.
Now i want to send a file from the server to the client. I am trying to use the jspsmartUpload to do it using the following code in a jsp file (save.jsp):
"<%@ page contentType="text/html;charset=ISO-8859-1" %>
<jsp:useBean id="dadosSessao" scope="session" class="beans.DadosSessao" />
// No cache.
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><%
// Initialization with jspSmartUpload v2.1
// Download
mySmartUpload.downloadFile("c:\\jakarta-tomcat-3.2.3\\webapps\\PS2\\WEB-INF\\classes\\uploaddir\\" + dadosSessao.getFichNameEUR);
When i click on the button which action is the save.jsp with the code above, he sends the text that is in the file but gives the following error:
"Error: 500
Location: /PS2/save.jsp
Internal Servlet Error:
java.lang.IllegalStateException: OutputStream is already being used for this request
at org.apache.tomcat.facade.HttpServletResponseFacade.getWriter(
at org.apache.jasper.runtime.JspWriterImpl.initOut(
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(
at org.apache.jasper.runtime.JspWriterImpl.flush(
at _0002fsave_0002ejspsave_jsp_1._jspService(
at org.apache.jasper.runtime.HttpJspBase.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.tomcat.core.ServletWrapper.doService(
at org.apache.tomcat.core.Handler.service(
at org.apache.tomcat.core.ServletWrapper.service(
at org.apache.tomcat.core.ContextManager.internalService(
at org.apache.tomcat.core.ContextManager.service(
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(
at org.apache.tomcat.service.TcpWorkerThread.runIt(
at org.apache.tomcat.util.ThreadPool$
Can anyone help me? I don't know where to look!
Claudia Vaz
Biju Nair
Ranch Hand

Joined: Dec 15, 2001
Posts: 31
This error comes when you try to use both response.getWriter() and response.getOutputStream() in the same servlet. Tomcat when compiling the JSP page to a servlet uses the getWriter() method. So the error may be caused as the jspSmartUpload may be using the response.getOutputStream() to write the contents of the file to the client for downloading.
I am not sure how to fix this. Will get back to you if I find out.

--: Biju Nair :--
I agree. Here's the link:
subject: send file to the client/ jspsmart
It's not a secret anymore!