<%
/ / Sometimes the user wants to download the file, but this file type is associated with the browser in the system, and the result is turned on in IE. // Common Word, Excel, PDF, etc. Therefore, transfer the file into a data stream to make the browser do not know the purpose of the file type.
// EXAMPLE:
String root
=
GetServletContext
(
)
.
GetRealPath
(
"/"
)
;
String path
= Request
.
GetParameter
(
"pat"
)
;
String name
= Request
.
GetParameter
(
"name"
)
;
Response
.
SetContentType
(
"unknown"
)
;
Response
.
AddHeader
(
"Content-Disposition"
,
"filename = /" ""
Name
"/"
)
;
Try
{
Java
.io
.Outputstream OS
= Response
.
Getputstream
(
)
;
Java
.io
.Fileinputstream fis
=
New Java
.io
.
FileInputStream
(root)
PATH
Name
)
;
Byte
[
] B
=
New
Byte
[
1024
]
;
INT i
=
0
;
While
(
(i
= FIS
.
reta
(B
)
)
>
0
)
{
OS
.
Write
(B
,
0
, I
)
;
}
FIS
.
Close
(
)
;
OS
.
Flush
(
)
;
OS
.
Close
(
)
;
}
Catch
(Exception E
)
{
}
%
>