|
32 | 32 | import org.springframework.http.ResponseEntity; |
33 | 33 | import org.springframework.stereotype.Controller; |
34 | 34 | import org.springframework.ui.Model; |
35 | | -import org.springframework.web.bind.annotation.ExceptionHandler; |
36 | | -import org.springframework.web.bind.annotation.PathVariable; |
37 | | -import org.springframework.web.bind.annotation.RequestMapping; |
38 | | -import org.springframework.web.bind.annotation.RequestMethod; |
39 | | -import org.springframework.web.bind.annotation.RequestParam; |
40 | | -import org.springframework.web.bind.annotation.ResponseBody; |
| 35 | +import org.springframework.web.bind.annotation.*; |
41 | 36 | import org.springframework.web.servlet.ModelAndView; |
42 | 37 |
|
43 | 38 | import com.alibaba.fastjson.JSONArray; |
@@ -163,7 +158,8 @@ public String newdata(HttpSession session, Model model) { |
163 | 158 |
|
164 | 159 | @RequestMapping("/export") |
165 | 160 | public ResponseEntity<byte[]> export(HttpSession session, |
166 | | - HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { |
| 161 | + HttpServletRequest request, HttpServletResponse response, |
| 162 | + @RequestHeader(value = "USER-AGENT") String userAgent) throws UnsupportedEncodingException { |
167 | 163 | SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); |
168 | 164 | List<User> users = userService.getUserList("desc", 10, 0); |
169 | 165 | String projectPath = request.getServletContext().getRealPath("export") |
@@ -207,37 +203,20 @@ public ResponseEntity<byte[]> export(HttpSession session, |
207 | 203 | POIExcelUtil.export(titles,columns, mps, file); |
208 | 204 | HttpHeaders headers = new HttpHeaders(); |
209 | 205 | headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); |
210 | | -// String filename="中文"; |
211 | | - String filename=""; |
212 | | - try { |
213 | | - filename = URLEncoder.encode(file.replace(projectPath, ""),"UTF-8"); |
214 | | - } catch (UnsupportedEncodingException e1) { |
215 | | - e1.printStackTrace(); |
| 206 | + String filename="中文"; |
| 207 | + if(userAgent.toLowerCase().indexOf("firefox") >= 0){ |
| 208 | + try { |
| 209 | + filename = new String((filename+file.replace(projectPath, "")).getBytes("UTF-8"),"iso-8859-1"); |
| 210 | + } catch (UnsupportedEncodingException e) { |
| 211 | + e.printStackTrace(); |
| 212 | + } |
| 213 | + }else { |
| 214 | + try { |
| 215 | + filename = URLEncoder.encode(filename+file.replace(projectPath, ""),"UTF-8"); |
| 216 | + } catch (UnsupportedEncodingException e1) { |
| 217 | + e1.printStackTrace(); |
| 218 | + } |
216 | 219 | } |
217 | | - |
218 | | -// try { |
219 | | -// filename=MimeUtility.encodeWord(filename); |
220 | | -// } catch (UnsupportedEncodingException e1) { |
221 | | -// // TODO Auto-generated catch block |
222 | | -// e1.printStackTrace(); |
223 | | -// } |
224 | | - |
225 | | -// try { |
226 | | -//// "gbk" |
227 | | -// filename=new String(filename.getBytes(),"iso-8859-1"); |
228 | | -// } catch (UnsupportedEncodingException e1) { |
229 | | -// e1.printStackTrace(); |
230 | | -// throw new RuntimeException(e1.getMessage()); |
231 | | -// } |
232 | | -// 中文编码 |
233 | | -// String userAgentStr = request.getHeader("user-agent"); |
234 | | -// if(userAgentStr!=null&&userAgentStr.toLowerCase().indexOf("msie")!=-1){//ie浏览器 |
235 | | -// filename = URLEncoder.encode(filename,"utf-8"); |
236 | | -// }else if(userAgentStr!=null&&userAgentStr.toLowerCase().indexOf("trident")!=-1){//ie11浏览器 |
237 | | -// filename = URLEncoder.encode(filename,"utf-8"); |
238 | | -// } |
239 | | -// filename = new String(filename.getBytes(),"ISO8859-1"); |
240 | | - |
241 | 220 | logger.debug("下载文件名字:{}",filename); |
242 | 221 | headers.setContentDispositionFormData("attachment",filename); |
243 | 222 | try { |
|
0 commit comments