| | |
| | | import java.io.PrintWriter; |
| | | import java.net.URLEncoder; |
| | | import java.sql.Timestamp; |
| | | import java.util.Calendar; |
| | | import java.util.Random; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Web帮助类 |
| | |
| | | * @throws Exception 异常 |
| | | */ |
| | | public static void download(String file, String fileName, HttpServletResponse res) throws Exception { |
| | | if (StringHelper.isNull(fileName)) { |
| | | fileName = URLEncoder.encode(FileHelper.getFileName(file), "UTF-8"); |
| | | if (StringHelper.isEmpty(fileName)) { |
| | | fileName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | } |
| | | fileName = URLEncoder.encode(fileName, "UTF-8").replace("+", "%20"); |
| | | |
| | | // 设置响应头中文件的下载方式为附件方式,以及设置文件名 |
| | | res.setHeader("Content-Disposition", "attachment; filename=" + fileName); |
| | | // 设置响应头的编码格式为UTF-8 |
| | | res.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + fileName); |
| | | // 设置响应头的编码格式为 UTF-8 |
| | | res.setCharacterEncoding("UTF-8"); |
| | | |
| | | // 通过response对象设置响应数据格式(如:"text/plain; charset=utf-8") |
| | |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取请求的参数值 |
| | | * |
| | | * @param req 请求 |
| | | * @param key 参数名 |
| | | * @return 参数值 |
| | | */ |
| | | public static String getReqParamVal(HttpServletRequest req, String key) { |
| | | Map<String, String[]> maps = req.getParameterMap(); |
| | | for (Map.Entry<String, String[]> entry : maps.entrySet()) { |
| | | if (entry.getKey().equalsIgnoreCase(key)) { |
| | | return null == entry.getValue() || 0 == entry.getValue().length ? null : entry.getValue()[0]; |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取请求的参数值 |
| | | * |
| | | * @param req 请求 |
| | | * @param key 参数名 |
| | | * @return 参数值 |
| | | */ |
| | | public static String[] getReqParamVals(HttpServletRequest req, String key) { |
| | | Map<String, String[]> maps = req.getParameterMap(); |
| | | for (Map.Entry<String, String[]> entry : maps.entrySet()) { |
| | | if (entry.getKey().equalsIgnoreCase(key)) { |
| | | return entry.getValue(); |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | } |