JSP file download: directly download the file and save it to the local device. It is not opened directly and there is no garbled code.

Source: Internet
Author: User

<%
//ProgramName: Download
// Program functions:
// Creation date: 08:49:52
// Created by: yanchao
// Update record: reason/content of the updated person's update date
//
%>

<% @ Page import = "Java. util. *" %>
<% @ Page import = "Java. Io. *" %>
<% @ Page import = "java.net. *" %>
<%
Response. setcontenttype ("application/X-download"); // set it to download application/X-Download
String filedownload = "/temp_lp/help/JSF. chm"; // relative path of the file to be downloaded
String filedisplay = "Help. chm"; // name of the file to be saved when the file is downloaded
String filenamedisplay = urlencoder. encode (filedisplay, "UTF-8 ");
Response. addheader ("content-disposition", "attachment; filename =" + filenamedisplay );

Try
{
Requestdispatcher Dis = application. getrequestdispatcher (filedownload );
If (DIS! = NULL)
{
Dis. Forward (request, response );
}
Response. flushbuffer ();
}
Catch (exception E)
{
E. printstacktrace ();
}
Finally
{

}
%>

<HTML>

<Script language = "JavaScript">
</SCRIPT>
</Html>

 

 

Related Article

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.