<% @ Page contentType = "text/html; charset = gb2312" import = "java. io. *" %>
<%
String url = request. getParameter ("url ");
String templateContent = "[InternetShortcut]" + "/n"
+ "URL = http: // localhost: 7001/jcewweb ";
String realfilename = "Jincheng Information Management System" + ". url ";
String upurl = request. getRealPath ("// upload // url //");
String filename = upurl + "//" + realfilename;
FileOutputStream fileoutputstream = new FileOutputStream (filename); // create a file output stream
Byte tag_bytes [] = templateContent. getBytes ();
Fileoutputstream. write (tag_bytes );
Fileoutputstream. close ();
Try {
File file = new File (upurl, realfilename );
BufferedInputStream bis = new BufferedInputStream (
New FileInputStream (file ));
Byte [] buffer = new byte [111000];
Realfilename = java.net. URLEncoder. encode (realfilename,
"GB2312 ");
Realfilename = java.net. URLDecoder. decode (realfilename,
"ISO8859_1 ");
Response. reset ();
Response. setCharacterEncoding ("UTF-8 ");
Response. setContentType ("application/x-download"); // different types of files correspond to different MIME types
Response. setHeader ("Content-Disposition ",
"Attachment; filename =" + realfilename );
OutputStream OS = response. getOutputStream ();
While (bis. read (buffer)> 0 ){
OS. write (buffer );
}
Bis. close ();
OS. close ();
} Catch (Exception e ){
E. printStackTrace ();
}
%>