Solution for displaying images with Chinese file names in jsp

Source: Internet
Author: User

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

 

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.