// JSP 部分代码,NetBeans 5.5 Beta2 版本下开发<%@page pageEncoding="UTF-8"%>
<%request.setCharacterEncoding ("UTF-8");%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
......
<a href="<%=request.getContextPath()%>/index.jsp?GetInfoBySex=<%=ndNoteDetails.getSex ()%>"><%=ndNoteDetails.getSex ()%></a>// 生成的链接中汉字正常,点击后,地址显示 "http://localhost:8084/Note/index.jsp?GetInfoBySex=男" 也正常
但 JSP 代码中
String InfoBySex = request.getParameter ("GetInfoBySex");
而 InfoBySex 得到的结果却为 \uffd 而不是汉字“男”。代码中已经全部设定为 UTF-8 编码,为什么还得不到正确的结果,请高手指教。
<%request.setCharacterEncoding ("UTF-8");%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
......
<a href="<%=request.getContextPath()%>/index.jsp?GetInfoBySex=<%=ndNoteDetails.getSex ()%>"><%=ndNoteDetails.getSex ()%></a>// 生成的链接中汉字正常,点击后,地址显示 "http://localhost:8084/Note/index.jsp?GetInfoBySex=男" 也正常
但 JSP 代码中
String InfoBySex = request.getParameter ("GetInfoBySex");
而 InfoBySex 得到的结果却为 \uffd 而不是汉字“男”。代码中已经全部设定为 UTF-8 编码,为什么还得不到正确的结果,请高手指教。
大概是这样,不知道有没有记错。比如tomcat默认是iso88591参数写到form中,用post方法提交或者拿到之后转换编码
目前的代码POST和GET提交方式都经过测试没有问题,唯独链接方式出问题
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">又发现个问题:
“计划一”该中文链接点击后获得的参数正确
“计划二”该中文链接点击后参数只有前两个字正确,第三个字又出现\ufffd
String temp = ndNoteDetails.getName ();
temp = java.net.URLEncoder.encode (temp,"UTF-8");
%>
<a href="index.jsp?GetInfoByName=<%=temp%>">
<%=ndNoteDetails.getName ()%>
</a>