帮忙解决这个URL编码问题?Jsp测试页
<%@ page language= "java " import= "java.util.* " pageEncoding= "UTF-8 "%>
<%@ page import= "java.net.URLDecoder "%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<base href= " <%=basePath%> ">
<title> My JSP 'codetest.jsp ' starting page </title>
<meta http-equiv= "pragma " content= "no-cache ">
<meta http-equiv= "cache-control " content= "no-cache ">
<meta http-equiv= "expires " content= "0 ">
<meta http-equiv= "keywords " content= "keyword1,keyword2,keyword3 ">
<meta http-equiv= "description " content= "This is my page ">
<!--
<link rel= "stylesheet " type= "text/css " href= "styles.css ">
-->
<script type= "text/javascript ">
<%
String v= " ";
if(request.getParameter( "v ")!=null)
{
v=URLDecoder.decode(request.getParameter( "v "), "UTF-8 ");
}
%>
alert( '这是从request中取得的数:\n\t <%=v%> ');
function run(args)
{
if(args== "n ")
{
var e=document.getElementById( "t ");
var v=e.value;
alert( "这是脚本直接取得的值,未经过脚本编码:\n\t "+v);
window.location.href= "codetest.jsp?v= "+v;
}
if(args== "y ")
{
var e=document.getElementById( "t ");
var v=encodeURI(e.value);
alert( "这是脚本直接取得的值,已通过encodeURI编码:\n\t "+v);
window.location.href= "codetest.jsp?v= "+v;
}
}
</script>
</head>
<body>
<input id= "t " type= "text " value= "test " />
<input type= "button " value= "N " onclick= "run( 'n ') " />
<input type= "button " value= "Y " onclick= "run( 'y ') " /> <br>
上面输入一个汉字看看,乱码问题
</body>
</html>
------解决方案--------------------我刚才帮你试了一下,好象可以,可能你的浏览器的编码设置问题,
------解决方案--------------------给大家推荐个
好的技术群 大家一起学习啊
32759197
------解决方案--------------------v=URLDecoder.decode(request.getParameter( "v "), "UTF-8 ");
把UTF-8换成GBK 试试。。
------解决方案--------------------如过是通过GET方法传递的参数如:url ../test.jsp?v=汉字