aspose file tools*
The moose likes Servlets and the fly likes cannot download files smaller than 8k (jspSmartUpload) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "cannot download files smaller than 8k (jspSmartUpload)" Watch "cannot download files smaller than 8k (jspSmartUpload)" New topic
Author

cannot download files smaller than 8k (jspSmartUpload)

Baka Neko
Greenhorn

Joined: Dec 09, 2003
Posts: 14
Hey everybody
Like mentioned above..Im using jspSmartUpload to upload files via jsp to a local path at my HD. Im also using this class for downloading. Everything is working great BUT i am not able to download files smaller than 8k This is driving me crazy, cause downloading other bigger files is working like a charm.
This is what Im getting for downloading files <8k:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.coyote.tomcat4.CoyoteResponse.getWriter(CoyoteResponse.java:614)
at org.apache.coyote.tomcat4.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:173)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:173)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:166)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:184)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:198)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:193)
at org.apache.jsp.geoeffnet_jsp._jspService(geoeffnet_jsp.java:51)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at dasProjekt.NeueVerbindung.service(NeueVerbindung.java:206)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:430)
at org.apache.jsp.oeffnen_jsp._jspService(oeffnen_jsp.java:79)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:534)

Hopefully someone in here got a great idea, how to solve this annoying problem.
TIA
BakaNeko
[ January 04, 2004: Message edited by: Baka Neko ]
[ January 04, 2004: Message edited by: Baka Neko ]
Baka Neko
Greenhorn

Joined: Dec 09, 2003
Posts: 14
Screw jspSmartUpload for downloading Ive wrote my own DownloadServlet..if anyone is interested. Here it is:
package dasProjekt;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* @author ooGAUoo
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DasDownloadServlet extends HttpServlet {

private ServletConfig servletConfig;
private ServletContext servletContext;
public void init(ServletConfig config) throws ServletException {

super.init(config);
servletConfig = config;
servletContext = servletConfig.getServletContext();
//TODO Method stub generated by Lomboz
}


public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {

ServletOutputStream out = res.getOutputStream();
String filename = req.getParameter("fn");
// kein file, also auch nix zum downen
if (filename == null) {

System.out.println("File nicht vorhanden");
return;
}
String pathName = "D:/upload2/" +filename;
//String pathName = getServletContext().getRealPath("/" + filename);
String contentType = getServletContext().getMimeType(pathName);

//if (contentType != null) res.setContentType(contentType);
//else
res.setContentType("application/x-msdownload");
res.setHeader ("Content-Disposition", "attachment; filename=\"" + filename + "\"");
// Return the file
try {
returnFile(pathName, out);
}
catch (FileNotFoundException e) {
System.out.println("Kein File gefunden: " + pathName);
}
catch (IOException e) {
System.out.println("Error beim Senden " + pathName + ": " + e.getMessage());
}
}



//TODO Method stub generated by Lomboz


public static void returnFile(String filename, OutputStream out) throws FileNotFoundException, IOException {

FileInputStream fis = null;
try {
fis = new FileInputStream(filename);
byte[] buf = new byte[4 * 1024]; // 4K buffer damit er auch kleinere files schluckt..
int bytesRead;
while ((bytesRead = fis.read(buf)) != -1)
out.write(buf, 0, bytesRead);
}
finally {
if (fis != null) fis.close();
}
}
}

Enjoy and its working real good
Baka out
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot download files smaller than 8k (jspSmartUpload)