大家好,我是讯享网,很高兴认识大家。
你需要把中文转码,然后在服务器进行解码操作
因为请求连接是不支持中文的
例子如下:
String string = "蔡君如";
String eStr = URLEncoder.encode(string, "utf-8");
System.out.println(eStr);
System.out.println(URLDecoder.decode(eStr, "utf-8"));
输出:
%E8%94%A1%E5%90%9B%E5%A6%82
蔡君如
上面那个是url用的编码格式,参数带那个 然后服务器解码:
new String(user.getName().getBytes("iso-8859-1"),"utf-8")
解码不用URLDecoder,直接得到参数的bytes,然后根据加码格式解码
下载文件只需把文件写入response的输出流即可:
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition", "attachment; filename=\""
+ new String(sss.getBytes("iso-8859-1"), "utf-8") + "\"");
OutputStream os = response.getOutputStream();
String pathString = request.getRealPath("/")
+ new String(sss.getBytes("iso-8859-1"), "utf-8");
InputStream is = new FileInputStream(new File(pathString));
byte[] buffer = new byte[2048];
int len = 0;
while ((len = is.read(buffer)) > 0) {
os.write(buffer, 0, len);
}
is.close();
os.flush();
os.close();
这样返回的就是个文件了~~
希望对你有帮助!
2025年URL 含中文 链接不上
URL 含中文 链接不上你需要把中文转码 然后在服务器进行解码操作 因为请求连接是不支持中文的 例子如下 String string 蔡君如 String eStr URLEncoder encode string utf 8 System out println eStr System out
虚拟成像技术_揭秘全息投影技术的前世今生
上一篇
2025-04-04 20:52
陈左宁院士:人工智能模型和算法的七大发展趋势
下一篇
2025-02-20 07:19
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/126083.html