URL 含中文 链接不上

你需要把中文转码,然后在服务器进行解码操作
因为请求连接是不支持中文的
例子如下:
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();
这样返回的就是个文件了~~

希望对你有帮助!
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值