首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

帮忙解决这个URL编码有关问题?Jsp测试页

2011-12-21 
帮忙解决这个URL编码问题?Jsp测试页%@pagelanguage java import java.util.* pageEncoding UTF-8

帮忙解决这个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=汉字


的话 应该把汉字转化成 UTF-8的编码在传过去[URLEncoder.encode( "汉字 ", "UTF-8 ")]
取的时候在转化回来
如果是tomcat的话 在server.xml 的
<Connector
port= "8080 "
中加入
URIEncoding= "UTF-8 "
最好在写个 过滤器
[解决办法]
zhaochunhui(没有烟抽的日子)

正解。

我以前用TOMCAT的时候就是这么解决的。

热点排行