本帖最后由 kippy 于 2011-10-03 12:51:57 编辑

解决方案 »

  1.   

    补充 也尝试过把request.setCharacterEncoding("UTF-8");写在filter里对*.jsp进行过滤,也是不行!
      

  2.   

    CSDN JAVA WEB板块都没人了吗????都去度假了??
      

  3.   

    request.getParameter("term").getBytes("ISO-8859-1"),"utf-8")进行编码
      

  4.   

    你用URL传值,要考滤编码问题的。
      

  5.   

    to miemie1320
    已经尝试过您的方法,也是不行,我在页面里打出编码格式均是UTF-8
    (<%out.println(request.getCharacterEncoding());%>)
      

  6.   

    to zhouyuqwert和yexiongMYBH
    能否具体一些?
    我现在主要是两个疑问,
    1、跳转过后的page1的url是http://localhost:8080/test/page1.jsp?term=2011春
    而不是平常见到的会把汉字转换成%...。
    2、我的参数“term=2011春”和“term=2011春夏秋冬”为什么后者不乱码而前者乱码,这个问题相当恼火了~~
      

  7.   

    你通过这句来获取参数试试:request.getParameter("term").getBytes("ISO-8859-1","utf-8");
      

  8.   

    参数传进去的时候就用URLEncode.encode方法转码下 或者js的urlencode
    比如如果你用java的需要转码的参数是String term = "2011春"就 term = URLEncode.encode(term,"utf-8")
    解码类似
    js的转码网上搜下 类似的
      

  9.   

    to JavaEthan
    应该是<%=new String(request.getParameter("term").getBytes("ISO-8859-1"),"utf-8")%>吧
    ,还是不行,page1.jsp的内容如下:
    This is next page. 
    request.getCharacterEncoding()=UTF-8 
    request.getParameter("term")=2011?
      

  10.   

    to zhouyuqwert
    用js转码搞定了,<script language="JavaScript">
    function toNextPage(){
    window.location = encodeURI("<%=path%>/page1.jsp?term=2011春");
    }
    </script>
    对应得到的url是“http://localhost:8080/test/page1.jsp?term=2011%E6%98%A5”。谢谢啊!!
    但是这样还是治标不治本,我应该在什么地方设置一下呢?各位大牛~~
      

  11.   

    如果是post方式获取
    在获取参数前加
    request.setCharacterEncoding("GBK");
    要说get方式获取的话,有时候是会出现乱码的情况,
    这不是因为你的代码写错了,可能是容器本身的问题,
    比如TOMCAT,所以你的去看看你的配置文件
      

  12.   

    indec.jsp:
    <%@ page contentType="text/html" pageEncoding="UTF-8"%><%
    String path = request.getContextPath();
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    %>
    <html>
    <head> </head>
    <body>
    <script type="text/javascript">
          function toNextPage()
          {
    window.location = "/jspTest/page1.jsp?term=2011春夏秋冬";
       }
           </script>

    This is first page. -- 13
    <br>
    request.getCharacterEncoding()=<%out.println(request.getCharacterEncoding());%><br>
    1:<%=path%>
    <input type="submit" value="go next page with parameters"
    onClick="toNextPage();" />
    </body>
    </html>page1.jsp:
    <%@ page contentType="text/html;" pageEncoding="UTF-8"%>
    <html>
      <head>
        <title>next page</title>
      </head>
      
      <body>
        This is next page. <br>
        request.getCharacterEncoding()=<%out.println(request.getCharacterEncoding());%><br>
        request.getParameter("term")=<%=request.getParameter("term")%><br>
      </body>
    </html>
    URL:为这样 http://localhost:8080/jspTest/page1.jsp?term=2011春夏秋冬
    我的是IE8
      

  13.   

    自己写个filter ,或者 
    <%=new String(request.getParameter("term").getBytes("ISO-8859-1"),"utf-8")%>
      

  14.   

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    把这个加到jsp页
      

  15.   

    话说以前还真没考虑过是否能设置下就默认的encode
    不过貌似有些浏览器就帮做了,如果是中文URL浏览器会转码
    比如你用Firefox试试,www.baidu.com/?a=中文
      

  16.   

    额 链接错了
    http://www.baidu.com/?a=中文
      

  17.   

    试了这么多 还是在js里做encodeURI管用,谢谢zhouyuqwert了!!