Skip to content

Commit 0114704

Browse files
committed
update
1 parent ca5c1e8 commit 0114704

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

src/main/java/cn/com/ttblog/ssmbootstrap_table/controller/IndexController.java

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@
3232
import org.springframework.http.ResponseEntity;
3333
import org.springframework.stereotype.Controller;
3434
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.*;
4136
import org.springframework.web.servlet.ModelAndView;
4237

4338
import com.alibaba.fastjson.JSONArray;
@@ -163,7 +158,8 @@ public String newdata(HttpSession session, Model model) {
163158

164159
@RequestMapping("/export")
165160
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 {
167163
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
168164
List<User> users = userService.getUserList("desc", 10, 0);
169165
String projectPath = request.getServletContext().getRealPath("export")
@@ -207,37 +203,20 @@ public ResponseEntity<byte[]> export(HttpSession session,
207203
POIExcelUtil.export(titles,columns, mps, file);
208204
HttpHeaders headers = new HttpHeaders();
209205
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+
}
216219
}
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-
241220
logger.debug("下载文件名字:{}",filename);
242221
headers.setContentDispositionFormData("attachment",filename);
243222
try {

0 commit comments

Comments
 (0)