A页面:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page pageEncoding="GB2312"%>
<%request.setCharacterEncoding("GB2312");%>
<input name="query" type="text" size="50" maxlength="50" />
&nbsp;&nbsp;<input type="submit" value="检索"/>B页面:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,com.net.*" errorPage="" %>
<%@page pageEncoding="GB2312"%>
<%request.setCharacterEncoding("GB2312");%>
String title = request.getParameter("query");
System.out.println(title);其中输出完全是问号加乱码,不知如何解决,谢谢!

解决方案 »

  1.   

    title=new String(title.getBytes("ISO8859_1"), "GBK")用这种方法试试
      

  2.   

    <%@page pageEncoding="GB2312"%> 
    <%request.setCharacterEncoding("GB2312");%> 这两个不要写B里面写String title = new String(request.getParameter("query").getBytes("UTF-8"),"GBK"); 
      

  3.   

    或者下面这个:
    java.net.URLDecoder.decode(request.getParameter("query"),"UTF-8");
      

  4.   

    楼主用的是get提交还是post提交? 最好还是用post吧.
      

  5.   

    我是要将Post传递的中文参数组成一个String,发送给一个远程接口,英文没有问题,只是中文问题!
      

  6.   

         
    A页面改成
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %> 
    <from action="B.jsp" method="post">
    <input name="query" type="text" size="50" maxlength="50" /> 
    &nbsp;&nbsp; <input type="submit" value="检索"/> 
    </from>     B页面改成
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,com.net.*" errorPage="" %> 
    <%String title = request.getParameter("query"); 
    System.out.println(title); %>页面传页面一般不用转码
      

  7.   


    String title = new String(request.getParameter("query").getbytes("ISO8859-1"),"GBK"); 转换一下就行了
      

  8.   

    看了大家的提议,我觉得按以下步骤应该可以解决问题(其实在几个月前我在公司写代码的时候也碰到过):
    1.在每个页面的头部加上<%@page contentType="text/html;charset="GBK"%>。
    2.在服务器的配置文件上加上URIEncoding="GBK"这一句,例如tomcat下的server.xml文件,具体加在什么地方呢?简单的说就是在配置端口的XML元素未尾,呵呵。
    3.配置filter,此时需要几个类文件,其实在tomcat文件里面可以找到源码的,具体怎么操作我在这里不多说了,这么晚了想睡了,详细介绍我博客里有,有兴趣的话可以去看看,http://hi.baidu.com/rascal_hu。
    做完以上步骤,问题应该不会存在了。
      

  9.   

    在tomcat下的server.xml文件
     <Connector port="8080" protocol="HTTP/1.1" maxThreads="150" connectionTimeout="20000" 
                   redirectPort="8443" />中把URIEncoding="GBK"加上去试试看吧。然后还需要做个过滤器。
      

  10.   

    <%@ page contentType="text/html;charset=UTF-8"%>
      

  11.   

    java文件是不是相同的格式,不统一肯定会乱码
      

  12.   

    请确保你所有的编码是UTF-8编码而不是GB2312,也不是GBK
      

  13.   

    1、在页面加: <%@ page language="java" pageEncoding="UTF-8" %> 
    2、加一个过滤器 public class MyFilter extends HttpServlet implements Filter {   private static final long serialVersionUID = 1L; 
    private FilterConfig filterConfig; 
        public void init(FilterConfig filterConfig) throws ServletException { 
            this.filterConfig = filterConfig; 
        }     public void doFilter(ServletRequest request, ServletResponse response, 
                             FilterChain filterChain) { 
            try { 
                request.setCharacterEncoding("UTF-8"); //设置中文 
                filterChain.doFilter(request, response); 
            } catch (ServletException sx) { 
                filterConfig.getServletContext().log(sx.getMessage()); 
            } catch (IOException iox) { 
                filterConfig.getServletContext().log(iox.getMessage()); 
            } 
        } 
        public void destroy() { 
        } 

    不过还有一点,你的整个程序要使用相同的编码
      

  14.   

    String title = new String(request.getParameter("query").getbytes("ISO8859-1"),"gb2312"); 
      

  15.   

    相信,你的
    <from action="" method="post">
    <input type="text"/>
    </form>
    应该是没有设成post..
      

  16.   

    #过滤文件
    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 CharacterEncodingFilter implements Filter {
    protected String encoding = null; protected FilterConfig filterConfig = null; protected boolean ignore = true; public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig;
    this.encoding = filterConfig.getInitParameter("encoding");
    String value = filterConfig.getInitParameter("ignore");
    if (value == null)
    this.ignore = true;
    else if (value.equalsIgnoreCase("true"))
    this.ignore = true;
    else
    this.ignore = false; } public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used
    if (ignore) {
    if (encoding != null)
    request.setCharacterEncoding(encoding);
    } // Pass control on to the next filter
    chain.doFilter(request, response); } public void destroy() {
    this.encoding = null;
    this.filterConfig = null;
    }}
    #web.xml 加载进去<filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>
    com.hwadee.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>gb2312</param-value>
    </init-param>
    <init-param>
    <param-name>ignore</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>

    <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
      

  17.   

    <from action="" method="post"> 
    <input type="text"/> 
    </form> 
      

  18.   

    一、使用更改Tomcat的方法。这个方法简单,但是需要改动的地方是服务器软件级别的,如果稍微变动系统将无法正确转码,移植性不高。1、来到tomcat目录,找到conf目录下的server.xml问价,打开,找到<Connector>标签,在最后添加URIEncoding=’GBK’
    2、在每个Jsp页面添加如下代码
    view plaincopy to clipboardprint?
    <%@ page pageEncoding=”gb2312″%>   
      
    <%@ page contentType=”text/html;charset=gb2312″%>   
      
    <%request.setCharacterEncoding(”gb2312″);%>  <%@ page pageEncoding=”gb2312″%><%@ page contentType=”text/html;charset=gb2312″%><%request.setCharacterEncoding(”gb2312″);%>编码方式也可以改成GBK,支持繁体中文。重启Tomcat,这一步很重要,否则可能看不到效果。这种方法对post测试成功。建议两种同步使用。二、使用JSP的scriptLetview plaincopy to clipboardprint?
    <%=new String(elValue.getBytes("iso-8859-1"),"GBK")%>  <%=new String(elValue.getBytes("iso-8859-1"),"GBK")%>三、使用自定义JSTL第一,编写自定义标签
    第二编写tag文件
    第三部署tag文件
      

  19.   

    要相对单个Element 转换可以用
    String title = new String(request.getParameter("query").getbytes("ISO8859-1"),"utf-8"); 要想一劳用逸的话就写一个filter