运行环境:tomcat 5.5.27    jdk1.5已经在tomcat的server.xml里增加了URLEncoding=utf-8的配置了问题是,通过编辑器传递一个参数内容为中文(utf-8)的时候,在java的action取参数的时候变成了乱码,试了好多转码问题都不行。这个效果跟直接在浏览器地址栏里输入是一样的。http://localhost:8080/search.action?title=中国
请问如何解决呢,看了好多中文乱码的帖子,也没发现好用的。修改前提: 1.server.xml的配置不能去,必须为utf-8的,如果修改了会对其他很多模块造成影响。           2.url传参的方式不能变,这个在编辑器一放,改不了的,是中文UTF-8的参数
试了在取参数前用response.setCharacterEncoding了,也不行

解决方案 »

  1.   

    GET请求使用URLEncoder[发送时编码] 和 URLDecoder[接收到解码]来解决中文问题
      

  2.   

    用Filter过滤一下这个地址,在Filter中处理成新的url再转过去
      

  3.   

    如楼上所说,如果没有源码,能加filter么如果不行,能知道服务段GET和POST处理流程一样么,如果一样,可以转为POST请求
      

  4.   

    没有源代码一样可以加,filter是加到web.xml中的,这个肯定是文本文件。public class MyFilter implements javax.servlet.Filter{.........}
      

  5.   

    学习下,filter可以配置到web.xml,但是具体filter如何处理?
      

  6.   

    可以试试这样转http://localhost:8080/search.action?title=中国 
     取得title的参数
     用String str =new String(title.getBytes("ISO-8859-1"),"UTF-8");
      

  7.   

    自己写一个过滤器:public class DoFilter implements Filter 
    { public void destroy() { 
    } public void doFilter(ServletRequest arg0, ServletResponse arg1, 
    FilterChain arg2) throws IOException, ServletException { arg1.setCharacterEncoding("GBK"); 
    arg2.doFilter(arg0, arg1); } public void init(FilterConfig arg0) throws ServletException { 
    } } 在web。xml中配置:
    <!-- 过滤器 --> 
      <filter> 
        <filter-name>encodingFilter </filter-name> 
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class> 
        <init-param> 
            <param-name>encoding </param-name> 
            <param-value>UTF-8 </param-value> 
        </init-param> 
        <init-param> 
            <param-name>forceEncoding </param-name> 
            <param-value>true </param-value> 
        </init-param> 
      </filter> 
      <filter-mapping> 
        <filter-name>encodingFilter </filter-name> 
        <url-pattern>*.jsp </url-pattern> 
      </filter-mapping>  
      <filter-mapping> 
        <filter-name>encodingFilter </filter-name> 
        <url-pattern>*.do </url-pattern> 
      </filter-mapping> 
      

  8.   

    楼主的问题,我也遇到过。整整搞了2天,上网阅尽无数高手文章。最后的解决方案是放弃tomcat5.5.27.改用5.5.20问题就解决的。
      

  9.   

    我当时做的是把tomcat的server.xml里增加了URLEncoding=GBK的配置,就没问题啦!
      

  10.   

    看我Blog
    http://blog.csdn.net/joyous/archive/2007/02/07/1504274.aspx基于Tomcat中间件处理JSP遇到中文时出现乱码解决方案如下:修改Tomcat的server.xml文件,该文件位于 tomcat/conf,红色部分为添加部分,也就是当前使用的HTTP端口的连接方式的设置。<Connector URIEncoding="utf-8" port="8080" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443" />运行代码内设置如下: JavaBean 和 Servlet 内需要处理中文的地方之前,或者所有函数最前端加上
    request.setCharacterEncoding ("UTF-8");
    response.setCharacterEncoding ("UTF-8");JSP代码中的 JAVA 字符编码设置<%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="java.net.URLEncoder"%>
    (好像上条语句并非必要)红色为制定JSP处理字符采用UTF-8编码处理方式。<%request.setCharacterEncoding ("UTF-8");%>
    JSP内JAVA代码设定接收参数为UTF-8编码JSP 内 HTML 头的编码设置
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Note Page</title>
    </head>
    <body>
    ……
    ……红色部分UTF-8制定HTML页面使用的编码方式<form action=index.jsp method="post"><h3>Please Input Your Name:</h3>
    <input type="text" size="30" name="yourname" value="" >
    <input type=submit value="提交">
    </form>接收代码如下:<%
    String temp1 = request.getParameter ("yourname");
    ……
    %>超链接参数传递方式略有不同,若只采用以上设定,遇中文参数,因编码不同,会导致部分文字信息丢失,所以在提交前务必进行编码。<a href="
    <%=request.getContextPath()%>/index.jsp?传递的参数名=
    <%=java.net.URLEncoder.encode (传递的汉字变量,"UTF-8")%>">
    <%=超链接热点显示内容%>
    </a>由 java.net.URLEncoder.encode 函数将要发送的变量解析为16进制数字编码,进行URL传递,接收代码如下:<%String str = request.getParameter ("传递的参数名");%>由此,获得参数后的 str 内将是正确的中文信息。以上操作将完全解决中文字符参数问题,当然附带数据库的话,编码格式也应该选择UTF-8