Lessons learned from downloading files using Jspsmartupload

Source: Internet
Author: User
Tags mail string
js| Download

Last night to download the file with Jspsmartupload, wrote a download page (download.jsp) as follows:

<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.io.*,mail.util.encoding"%>
<jsp:usebean id= "mysmartupload" scope= "page" class= "Com.jspsmart.upload.SmartUpload"/>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<%
String filename =encoding.encodingunicode (request.getparameter ("filename"));
Mail. Dbbase Dbbase=mail. Dbbase.getinstance ();
String Path=dbbase.getpath ();
Class
Mysmartupload.initialize (PageContext);
Set contentdisposition NULL to prevent the browser from automatically opening the file.
Ensure that you click on the link to download the file. If not set, the downloaded file name extension is
Doc, the browser will automatically open it in Word. When the extension is PDF,
The browser will be opened with Acrobat.
Mysmartupload.setcontentdisposition (NULL);
Download files
if (filename!=null) {
Mysmartupload.downloadfile (Path+filename);
}
%>
</body>

When the download is performed, the file is downloaded correctly, but it always complains.

Java.lang.IllegalStateException:getOutputStream () has already been called for this response

Later found that the implementation of the downloaded page, outside the scope of the Java script (that is, outside the <% ...%>), do not include HTML code, space, carriage return or newline characters, and some words will not download correctly. If not, you can add a line break between%><% in the above source code, and then download it to ensure error. Because it affects the data stream returned to the browser, it causes parsing errors.

Fix the problem after modification.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.