download file
1. The use of a label directly come downloads
Some of the contents of the browser will automatically parse
Browser can not parse the file will be downloaded
2. By transmitting requests come Servlet downloads
Servlet by sending a request to the server to send the file name
After sending to the server, receiving the file name parameter to get the absolute address file
Written by a stream of browsers come and go
I had to tell what type of file
Browser based on MIME types to identify the type of
this.getServletContext (). getMimeType ( "filename")
Provided type of response
res.setContentType("MIME类型")
Setting response headers, to tell the browser not to resolve, in the form of an attachment is opened
res.setHeader("Content-Dsiposition","attachment;filename="+文件名)
Chinese name solve the garbage problem
Gets Chinese parameter error problem
Tomcat high version of the new features: that is, in strict accordance with RFC 3986 specifications visit parsing, and RFC 3986 specification defines Url allowed only contain letters (a-zA-Z), numbers (0-9), -_ ~. four special characters as well as all reserved characters (RFC3986 specified in the following characters are reserved characters: * '();:! @ & = + $, / # []?)
solution
... / conf / catalina.properties, find the last comment out the line # tomcat.util.http.parser.HttpParser.requestTargetAllow = |, into tomcat.util.http.parser.HttpParser.requestTargetAllow = | {}, {} represents the release
1. The byte code string obtained by the obtaining of the parameters, and then re-encoded using utf-8
2. When setting up open an attachment, different browsers will decode the default name
So depending on the browser, then they have to be encoded on the name, then add the file name
To encode the file name
Different browsers coding is not the same
First acquisition agent, remove the browser type
Coded according to different types of browsers
Sample code:
Old nine school community members produced