<%
// Sometimes the user wants to download the file, but the file type is associated with the browser in the system, and the result is opened in IE.
// Common examples include Word, Excel, and PDF. Therefore, converting a file into a data stream allows the browser to download the file without knowing its file type.
// Example:
// <A href = "Download. jsp? Path = img/&name=test.gif "> download image </a>
String root = getservletcontext (). getrealpath ("/");
String Path = request. getparameter ("path ");
String name = request. getparameter ("name ");
Response. setcontenttype ("unknown ");
// Note: If attachment is removed from the following line of code, ie will automatically open the file.
Response. addheader ("content-disposition", "attachment; filename =/" "+ name + "/"");
Try
{
Java. Io. outputstream OS = response. getoutputstream ();
Java. Io. fileinputstream FCM = new java. Io. fileinputstream (root + path + name );
Byte [] B = new byte [1024];
Int I = 0;
While (I = FCM. Read (B)> 0)
{
OS. Write (B, 0, I );
}
FCM. Close ();
OS. Flush ();
OS. Close ();
}
Catch (exception E)
{}
%>