About tomcat file download configuration, tomcat file download configuration

Source: Internet
Author: User

About tomcat file download configuration, tomcat file download configuration
Preface

  • Tomcat File Download
  • Disable tomcat directory list browsing
  • Tomcat cannot download attachments with Chinese names

File downloading is a common feature in Java Web projects. Recently, we found that the file downloading feature can be completed through the built-in features of tomcat.

Tomcat File Download
  1. In eclipseWebContentCreate a folder named download_file. This folder is used to download files and then start the tomcat server,
    In the browser, the URL: http: // localhost: 8080/project name/download_file/file name can be used to download the file. (Note that the file name must contain a suffix.) 1


Figure 1

Disable tomcat directory list browsing
  1. In fact, the above has completed a simple file download function, but there is a problem, if the url is followed by download_file without any file name, tomcat will traverse the download_file file directory by default (2 ),


Figure 2
In this way, it is not safe enough for others to download other files at will. Tomcat configuration is involved here. Open/conf/web. xml in the tomcat directory.

 <servlet>        <servlet-name>default</servlet-name>        <servlet-class>        org.apache.catalina.servlets.DefaultServlet        </servlet-class>        <init-param>            <param-name>debug</param-name>            <param-value>0</param-value>        </init-param>        <init-param>            <param-name>listings</param-name>            <param-value>false</param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>

 

 

Change the value of listings to false to disable tomcat from directly accessing the file directory.

Tomcat cannot download attachments with Chinese names
  1. There is still a flaw in downloading the above file. When the file name contains Chinese characters, the file in the directory cannot be found. This is the/conf/server under the tomcat directory. add the above Code to the xml file and add it to the <Connector> \ tag.DisableUploadTimeout = "true" URIEncoding = "UTF-8"You can recognize Chinese file names.
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" disableUploadTimeout="true" URIEncoding="UTF-8"/>

 

 

Finally, if you modify the configuration file and restart the eclipse tomcat service, you only need to delete the tomcat service and create a new one.

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.