Completely resolved Chinese documents to download and download the contents of the documents hash issues

  Abstract: Complete solution for Chinese documents to download and download the contents of the documents hash issues 

  <tr> <td> 

  , Wrote a Download.jsp document can be downloaded file hash solve problems (such as: DOC, XSL documents, etc.). 
  Later that were encountered Chinese documents, file downloads will be error ~ ~ ~ ~ 
  Today, through Download.jsp rewrite the original document has been completely resolved this issue ~ 
  Now, a set of documents to the method of uploading and downloading to paste up ~ ~ ~ to everybody's reference !~!~!~!~! 
  Author: pharaohs of ancient Egypt 
  ————————————————– ————————————————– ————— 
  Test Environment: WEBLOGIC 8.1, WIN XP SP4, IE 6.0 
  ————————————————– — 
  Upload files: 
—————————————–
  Preparation: Import famous SmartUpload.jar Package 
  Upload.jsp document 
  ————————————————– ———- 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 
<%
  Request.setCharacterEncoding ( "gb2312"); / / is very important, otherwise encountered Chinese on the wrong ~ 
%>
<head>

  </ Head> 
  <body LeftMargin=0 topMargin=0> 
  <table Width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#DEE7EF"> 
<tr>
  <td Align="center"> 
  <form Action="upload_ok.jsp" method=post name="Upload" enctype="multipart/form-data"> 


  Please enter the annex of the document required for the project path * 



  <table Width="317" border=0 cellPadding=0> 

<tr>
  <td Align=right vAlign=center nowrap> Annex Path: </ td> 
  <td> <input Type="file" name="file" style="border: 1px #FFFFFF solid;background:#efefef"> * </ td> 
  </ Tr> 
  <tr Align="center"> 
  <td Height=60 colspan="2" vAlign=center nowrap> <input style="height:22px" name=B1 type=submit value="确定"> 
  <input Style="height:22px" name=B2 type=reset value="取消"> 
  </ Td> 
  </ Tr> 

  </ Table> 
  </ Form> 
  </ Td> 
  </ Tr> 
  </ Table> 
  </ Body> 
  ————————————————– ———- 
  Upload_ok.jsp document 
  ————————————————– ———- 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 
  <% @ Page import = "com.jspsmart.upload .*"%> 
<head>

  </ Head> 
  <body LeftMargin=0 topMargin=0> 

  <table Width="80%" border="0" cellpadding="0" cellspacing="0" bgcolor="#DEE7EF"> 
<tr>
  <td Align="center"> 
<%
  Int count = 0; 
  String fileName = null; 
  MySmartUpload.initialize (pageContext); 
  MySmartUpload.upload (); 
  Com.jspsmart.upload.File myFile = mySmartUpload.getFiles (). GetFile (0); 
  If (! MyFile.isMissing ()) ( 
  / / String ext = myFile.getFileExt ();// get suffix 
  FileName = myFile.getFileName (); 
  MyFile.saveAs ( "/ files /" + fileName); / / you must file documents folder where the relative path 
  Out.println ( "document:" fileName + + "upload success! 
  File Size: "+ myFile.getSize () +" kb 
");
  ) 
%>
  </ Body> 
  ————————————————– ———- 

  Download: 
—————————————–
  Hyperlinked documents written examples: 
  <% String fname = "Chinese testing. Xsl" / / Suppose your file name: Chinese test. Xsl 
%>
  "> Download 
  Super-written document examples -2 re-connect with utf-8 encoding of the document were: 
  <% @ Page contentType = "text / html; charset = gb2312" session = "true"%> 
  <% String name = java.net.URLEncoder.encode ( "World. Doc," "UTF-8 "));%>"> World. Doc 

  Download.jsp document 
  ————————————————– ———- 
<%
  Java.io.BufferedInputStream bis = null; 
  Java.io.BufferedOutputStream bos = null; 
  Try ( 
  String filename = request.getParameter ( "filename"); 
  Filename = new String (filename.getBytes ( "iso8859-1"), "gb2312"); 
  Response.setContentType ( "application / x-msdownload"); 
  Response.setHeader ( "Content-disposition", "attachment; filename =" + new String (filename.getBytes ( "gb2312"), "iso8859-1")); 
  Bis = new java.io.BufferedInputStream (new java.io.FileInputStream (config.getServletContext (). GetRealPath ( "files /" + filename))); 
  Bos = new java.io.BufferedOutputStream (response.getOutputStream ()); 
  Byte [] = new byte buff [2048]; 
  Int bytesRead; 
  While (-1! = (BytesRead = bis.read (buff, 0, buff.length))) ( 
  Bos.write (buff, 0, bytesRead); 
  ) 
  ) 
  Catch (Exception e) ( 
  E.printStackTrace (); 
  ) 
  Finally ( 
  If (bis! = Null) bis.close (); 
  If (bos! = Null) bos.close (); 
  ) 
%>

  </ Td> </ tr> </ table> 
  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , , ,

Releated Java Articles

Comments

Leave a Reply