Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

send file to the client/ jspsmart  RSS feed

Claudia Vaz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!