@@ -0,0 +1,1784 @@
+package cn.com.lemon.base;%0A%0Aimport java.io.UnsupportedEncodingException;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A/**%0A * Static utility methods pertaining to %7B@code Downloads%7D primitives.%0A * %3Cp%3E%0A *%0A * @author shellpo shih%0A * @version 1.0%0A */%0Apublic final class Downloads %7B%0A%0A%09private Downloads() %7B%0A%09%7D%0A%0A%09/**%0A%09 * Set the (%7B@code HttpServletResponse%7D header,when cross-domain request api%0A%09 * base on https/http protocol%0A%09 * %0A%09 * @param response%0A%09 * @return%0A%09 */%0A%09public static void response(HttpServletResponse response) %7B%0A%09%09response.setHeader(%22Pragma%22, %22No-cache%22);%0A%09%09response.setHeader(%22Cache-Control%22, %22no-cache%22);%0A%09%09response.setDateHeader(%22Expires%22, 0);%0A%09%09response.setHeader(%22Access-Control-Allow-Origin%22, %22*%22);%0A%09%7D%0A%0A%09/**%0A%09 * In order to solve the problem of Chinese language,%0A%09 * %3Cp%3E%0A%09 * caused by the problem.The file content of the header is preferred for%0A%09 * filename setting.%0A%09 * %3Cli%3ESafari:%7B@code ISO%7D%3C/li%3E%0A%09 * %3Cli%3EOther:%7B@code URLEncoder%7D%3C/li%3E%0A%09 * %0A%09 * @param fileName%0A%09 *            the file name,or the file name contains Chinese character%0A%09 * @param request%0A%09 * @return %7B@code String%7D the %7B@code HttpServletResponse%7D%7D%0A%09 */%0A%09public static String contentDisposition(String fileName, HttpServletRequest request) %7B%0A%09%09String userAgent = request.getHeader(%22User-Agent%22);%0A%09%09try %7B%0A%09%09%09if (userAgent.contains(%22Safari%22)) %7B%0A%09%09%09%09byte%5B%5D bytes = fileName.getBytes(%22UTF-8%22);%0A%09%09%09%09fileName = new String(bytes, %22ISO-8859-1%22);%0A%09%09%09%09return String.format(%22attachment; filename=%5C%22%25s%5C%22%22, fileName);%0A%09%09%09%7D else %7B%0A%09%09%09%09fileName = java.net.URLEncoder.encode(fileName, %22UTF-8%22);%0A%09%09%09%09return %22attachment;filename=%22 + fileName;%0A%09%09%09%7D%0A%09%09%7D catch (UnsupportedEncodingException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09return %22attachment;filename=%22 + fileName;%0A%09%09%7D%0A%09%7D%0A%7D%0A

add Downloads