response.setContentType("gb2312");
或者
String test=new String(request.getParameter("test").getBytes("ISO-8859-1"),"gb2312");

解决方案 »

  1.   

    在Filter或ActionServlet文件中加入一句
    httpServletRequest.setCharacterEncoding("GBK");
    或String test=new String(request.getParameter("test").getBytes("ISO8859_1"), "GBK");
      

  2.   

    还是不行啊,我没用struts,只是jsp
    我把所有的代码贴上
    <%@ page language="java" import="java.util.*,java.net.*" pageEncoding="GB2312" contentType="text/html; charset=gb2312"%>
    <%
    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 'sender.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">
        -->
      </head>
      
      <body>
         <%
            response.setContentType("gb2312");     
         String url = "receiver.jsp?test=谭老师";
         response.sendRedirect(response.encodeRedirectURL(url));
        %>  </body>
    </html>
      

  3.   

    String test=new String(request.getParameter("test").getBytes("ISO8859_1"), "gb2312");
    ISO8859_1要看环境是不是这个字符集
      

  4.   

    谢谢你!
    web.xml是这样的<?xml version="1.0" ?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>  <welcome-file-list>
        <welcome-file>search.jsp</welcome-file>
      </welcome-file-list>
      
      <context-param>
        <param-name>weblogic.httpd.inputCharset./*</param-name>
        <param-value>GB2312</param-value>
      </context-param>
      
    </web-app>
      

  5.   

    System.getProperty("file.encoding")
    可以获得当前环境的字符集
      

  6.   

    response.setContentType("gb2312");
    就可以解决中文显示问题了。
    不过最好还是做个刷新功能。
      

  7.   

    你得想办法把 "receiver.jsp?test=谭老师" 转化成 "receiver.jsp?test=%AB%12%CD%34..." 这种格式,而用什么编码转换要看你的 receiver.jsp 是什么编码的。如果是 gbk 的:
    那么,"receiver.jsp?test=" + GBK_URLEncode("谭老师")public static String GBK_URLEncode( String str ) throws UnsupportedEncodingException
    {
        StringBuffer buf = new StringBuffer();
        byte [] b = str.getBytes("GBK");    for(int i=0; i<b.length; i++)
        {
            if( b[i] > 32 && b[i] < 128 )
                buf.append( b[i] );
            else
            {
                buf.append( "%" );
                buf.append( Integer.toHexString((int)0x200 + b[i]).substring(1) );
            }
        }    return buf.toString();
    }
      

  8.   

    如此简单......
    String s = URLEncoder.encode("中文", "utf-8");
    System.out.println(s);