我做了个AJAX下拉框取值,我用的是String region=request.getParameter("region");取值,取下来的值是乱码,赋值我是这样赋的onchange="showList1(this.options[this.options.selectedIndex].value),这样有问题吗?或是如果采用这样的方式我怎么转码?我JSP是request.setCharacterEncoding("GBK");UTF-8也用过了!!谢谢

解决方案 »

  1.   

    在取参数时加(JSP是<%request.setCharacterEncoding("GBK");%>
      

  2.   

    问题解决办法:   
      1)修改server.xml,在connector标签中增加URIEncoding="gb2312"   
      2)对url编码   
          java.net.URLEncoder.encode(   url   );   
      注意:url的起始如果非中文如   "/test/中文/中国.jsp"   
      则应该写成"/test/"   +   java.net.URLEncoder.encode(   "中文/中国.jsp"   );   
      意思是只对中文编码,但是   "中文/中国.jsp"中的"/"没有问题   
      

  3.   

    我要对我的页面全部改成 "中文/中国.jsp"中的"/"?我不是太明白楼上所说,能说的再详细一点吗?谢谢
      

  4.   

    下拉框要取value值,不要取文本值
      

  5.   

    onchange="showList1(this.option[this.options.selectedIndex].value)改成
    onchange="showList1(encodeURL(this.option[this.options.selectedIndex].value))
      

  6.   

     <%request.setCharacterEncoding("GBK");%>这个比较好用,
    你也可以取时用ENCODE() DECODE()
      

  7.   

    在ajax中出现乱码我的问题我在csdn中解决过,lz没有所搜吧有两种方法可以:1 可以用ajax的post提交var getUrl = "/xxx/xxx.do?method=xxx";            
    var post = "aaa="+bbb+"&ccc=哈哈&mySortCode=的发送发式"        
    post = encodeURI(post);
    post = encodeURI(post);//一定要两次,很关键然后用ajax的post提交过去就好了2  加密,给中文部分加密。上面两中都可行,我一般用第一种
      

  8.   

    过滤器配置  
    <filter>
    <filter-name>encoding</filter-name>
    <filter-class>
    filter.FilterEncoding
    </filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>gbk</param-value>
    </init-param>
    </filter>package filter;import java.io.IOException; 
    import javax.servlet.Filter; 
    import javax.servlet.FilterChain; 
    import javax.servlet.FilterConfig; 
    import javax.servlet.ServletException; 
    import javax.servlet.ServletRequest; 
    import javax.servlet.ServletResponse; 
    public class FilterEncoding implements Filter 

    protected String encoding;          // 接收字符编码
    protected boolean ignore;            // 是否忽略大小写
    protected FilterConfig filterConfig; // 初始化配置 public void init(FilterConfig filterConfig) throws ServletException 
    {
    // 从web.xml文件中读取encoding的值
    encoding = filterConfig.getInitParameter("encoding"); 
    // 从web.xml文件中读取ignore的值
    String value = filterConfig.getInitParameter("ignore"); 
    // 以下三种情况均为忽略大小写
    if(value == null) 

    ignore = true; 
    }
    else if(value.equalsIgnoreCase("yes")) 

    ignore = true; 

    else if(value.equalsIgnoreCase("true")) 

    ignore = true; 


    // doFilter方法
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException 
    {
    if(ignore || request.getCharacterEncoding() == null) 
    {
    // 如果为空先从web.xml中得到
    String encoding = selectEncoding(request); 
    if(encoding != null) 
    {
    // 设置字符集编码
    request.setCharacterEncoding(encoding); 
    }
    }
    // 继续执行
    chain.doFilter(request, response); 

    // 得到字符编码
    private String selectEncoding(ServletRequest request) 

    return encoding; 

    public void destroy() 

      

    }
    如果是url的get提交参数带中文的 
    可以改下面这个文件,加入一个URIEncoding="GBK" 
    X:\Tomcat 5.5\conf\Server.xml 
      <Connector 
            port="8080" 
            redirectPort="8443" 
            minSpareThreads="25" 
            connectionTimeout="30" 
            maxThreads="150" 
            maxSpareThreads="75" 
    URIEncoding="GBK"
    <%@ page contentType="text/html;charset=gbk"%>   //此处的charset的值要和web.xml里的  <param-value></param-value>值一样
      

  9.   

    我记得有人告诉我这么用,你试试:
    String region = new String(request.getParameter("region").getBytes("ISO-8859-1"),"GB2312");
      

  10.   

    改成POST提交.URL是通过URLENCODING和URLDECODING来编解码的.