JSP display Chinese filename and absolute path under the image solution _jsp programming

Source: Internet
Author: User
(1) JSP displays the Chinese file name picture
method One, change the Server.xml file in Tomcat to:
Copy Code code as follows:

<connector port= "8080" maxhttpheadersize= "8192"
maxthreads= "minsparethreads=" maxsparethreads= "75"
Enablelookups= "false" redirectport= "8443" acceptcount= "100"
connectiontimeout= "20000" disableuploadtimeout= "true" uriencoding= "GBK"/>

JSP page:
Copy Code code as follows:

<%@ page import= "Java.net.URLEncoder"%>


method Two, in Tomcat's Server.xml
Add an attribute: uriencoding= "UTF-8"
after modification for
Copy Code code as follows:

<connector port= "8080" protocol= "http/1.1"
maxthreads= "connectiontimeout=" "20000"
Redirectport= "8443" uriencoding= "UTF-8"/>

(2) display the picture under the absolute path
train of Thought: Read the file stream from the files on the local hard drive and use the servlet to read the pictures on the JSP page
Servlet Code:
Copy Code code as follows:

public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Response.setcontenttype ("text/html; Charset=utf-8 ");
Response.setcontenttype ("Image/jpeg"); Format picture formatting, which can be ignored
FileInputStream fis = new FileInputStream ("d:/ftp/xxx.jpg");
OutputStream OS = Response.getoutputstream ();
try {
int count = 0;
byte[] buffer = new byte[1024*1024];
while ((count = fis.read (buffer))!=-1)
Os.write (buffer, 0, count);
catch (IOException e) {
E.printstacktrace ();
}finally {
if (os!=null)
Os.close ();
if (FIS!= null)
Fis.close ();
}
}

Refer directly to
Access the JSP page to display the picture.
I think the method is the simplest one, hehe! I have tried the method one, can solve my Chinese filename does not show the problem, in some thank 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.