(1) jsp display of images with Chinese file names
Method 1: Change the server. xml file in Tomcat:
Copy codeThe Code is as follows: <Connector port = "8080" maxHttpHeaderSize = "8192"
MaxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
EnableLookups = "false" redirectPort = "8443" acceptCount = "100"
ConnectionTimeout = "20000" disableUploadTimeout = "true" URIEncoding = "GBK"/>
Jsp page:Copy codeThe Code is as follows: <% @ page import = "java.net. URLEncoder" %>
Method 2: server. xml in tomcat
Add a property: URIEncoding = "UTF-8"
After modification:Copy codeThe Code is as follows: <Connector port = "8080" protocol = "HTTP/1.1"
MaxThreads = "150" connectionTimeout = "20000"
RedirectPort = "8443" URIEncoding = "UTF-8"/>
(2) display the image in the absolute path
Ideas: Read files from the local hard disk and use servlet to read images.
Servlet code:Copy codeThe Code is as follows: public void doGet (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, IOException {
Response. setContentType ("text/html; charset = UTF-8 ");
Response. setContentType ("image/jpeg"); // sets the image format, which can be ignored here
FileInputStream FCM = new FileInputStream ("D:/ftp/xxx.jpg ");
OutputStream OS = response. getOutputStream ();
Try {
Int count = 0;
Byte [] buffer = new byte [1024*1024];
While (count = FS. read (buffer ))! =-1)
OS. write (buffer, 0, count );
} Catch (IOException e ){
E. printStackTrace ();
} Finally {
If (OS! = Null)
OS. close ();
If (FS! = Null)
FCM. close ();
}
}
Directly reference
Access the jsp page to display the image.
I think the first method is the simplest! I have tried method 1 and can solve the problem of not displaying the Chinese file name. Thank you very much for xiaoxiaoxuewen.