惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - 重粒子

文件在线预览doc,docx转换pdf(一) vue中集成pdfjs自定义分页 使用 vs code 搭建vue项目(一) post文件下载 css 文本超出2行就隐藏并且显示省略号 js监听全屏下的esc事件 js实现全屏和缩放 ionic 侧栏菜单用法 weblogic获取应用目录路径(war包) 使用pdf.js预览实现读取服务器外部文件 js禁用浏览器后退 java批量将多文件打包成zip格式 Angularjs自定义指令计算浏览器高度 AngularJS封装webupload实现文件夹上传 jquery监听滚动条 pdf预览(pdf.js) (钉钉)第三方WEB网站扫码登录 $q的基本用法 巧用 Jersey RESTful WebService框架解决文件上传乱码
Jersey RESTful WebService框架学习(八)文件下载防乱码
重粒子 · 2018-01-28 · via 博客园 - 重粒子

最近在做下载时候  不同浏览器下载的文件一直出现乱码,不知道怎么设置文件的编码,百度许久,找到一个解决办法如下

/**
	 * 文件下载
	 * @param request
	 * @return
	 */
	@GET
	@Path("/d")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
	public Response  download(@QueryParam("filemd5") String viFileMd5,@QueryParam("filename") String viFileName,@Context HttpServletResponse response) {
		File nFile = new File(WebConfig.MAIN_UPLOAD_TEMP_PATH + File.separator+ viFileMd5);
		// 如果文件不存在,提示404
		if (!nFile.exists()) {
			return Response.status(Response.Status.NOT_FOUND).build();
		}
		String nFileName = null;
		try {
			nFileName = URLEncoder.encode(viFileName, "UTF-8");
			response.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		return Response.ok(nFile).header("Content-disposition","attachment;filename=" + nFileName+";filename*=utf-8''"+nFileName).header("Cache-Control", "no-cache").build();
	}

设置header("Content-disposition","attachment;filename=" + nFileName+";filename*=utf-8''"+nFileName)即可