The solution of displaying Chinese file name and image under absolute path in JSP


(1) JSP shows the image of Chinese file name
Method 1: the server.xml Change to:

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=”” %>
<img src=”…../…/ URLEncoder.encode (“picture name. JPG”, “GBK”) “/ >

Method 2. In Tomcat server.xml
Add an attribute: 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) Show pictures in absolute path
thinking: read the file stream from the local hard disk, and use the servlet to read the image and display it on the JSP page
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”); / / set the image format, which can be ignored here
FileInputStream fis = new FileInputStream(“D:/ftp/xxx.jpg”);
OutputStream os = response.getOutputStream();
try {
int count = 0;
byte[] buffer = new byte[1024*1024];
while ( (count = != -1 )
os.write(buffer, 0, count);
} catch (IOException e){
}finally {
if(fis != null)

Directly refer to < img SRC = “servlet address” / > in the page
Visit the JSP page to display the image.
I think method one is the simplest, ha ha! I have tried method 1, which can solve the problem that my Chinese file name is not displayed. Thank you very much.