Solutions for displaying Chinese file names and images in absolute paths in jsp

Source: Internet
Author: User

(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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.