request 取数据时一部分中文显示正常,一部分中文乱码(奇怪!)
由list.jsp页面--->do_download.jsp页,在do_download.jsp页得到list.jsp传过来的值,但部分中文显示乱码而不是全部。如“接口简要说明.doc”则显示 “接口简要说??doc”很奇怪!希望高手能够帮忙!
list.jsp主要内容:
<%@ page contentType="text/html; charset=UTF-8" errorPage="../console/error.jsp"%>
<input type="checkbox" name="attachCheck" value="<%=fileName %>"><a href="do_download.jsp?fileName=<%=fileName %>&archrec_id=<%=archrec_id %>"><%=fileName %></a>
do_download.jsp主要内容:
<%@ page contentType="text/html;charset=UTF-8"
import="com.eharmony.psbdais.recordsaccession.jspsmart.*" errorPage="../console/error.jsp"%>
String fileName=request.getParameter("fileName");
fileName=ParamUtils.transFormpara(fileName);//ParamUtils的transFormpara方法作用就是将ISO-8859-1 转换到 UTF-8 ,代码见最后。
步骤:点击list.jsp中的href链接到do_download.jsp
1.假设现在list.jsp中参数fileName=“新建 文本文档.txt”;则在do_download.jsp页得到的值是“新建 文本文档.txt”,是对的。
2.假设现在list.jsp中参数fileName=“接口简要说明.doc”;则在do_download.jsp页得到的值是“接口简要说??doc”,这样就有乱码,不知道该怎么解决。希望高手能够帮忙指点!
ParamUtils类中transFormpara方法:
public static String transFormpara(String name) {
try {
if (name==null||name.equals("")) {
return "";
}
System.out.println(new String(name.getBytes("ISO-8859-1"),"UTF-8"));
return new String(name.getBytes("ISO-8859-1"),"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
return name;
}
}