(1) jsp display of images with Chinese file names
Method 1: Change the server. xml file in Tomcat:
<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:
<% @ Page import = "java.net. URLEncoder" %>
Method 2: server. xml in tomcat
Add a property: URIEncoding = "UTF-8"
After modification:
<Connector port = "8080" protocol = "HTTP/1.1"
MaxThreads = "150" connectionTimeout = "20000"
RedirectPort = "8443" URIEncoding = "UTF-8"/>
(2) display the image in the absolute path
Idea: Read the file stream from the local hard disk and use servlet to read the image and display it on the jsp page.
Servlet code:
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.