response.setCharacterEncoding("gb2312")与你的getXXX有关,
response.setContentType("text/html;charset=gb2312")与显示页面有关。我是这么理解,你可以看API呀。。

解决方案 »

  1.   

    同意naxin(痴呆男人--我痴呆,我自豪!!) 
    那几个应该是改变显示数据或字的字体咯.
      

  2.   

    没有 response.setCharacterEncoding("gb2312")只有 request.setCharacterEncoding("gb2312")
      

  3.   

    有response.setCharacterEncoding(Constants.CHARCODE);
      

  4.   

    response.setCharacterEncoding(Constants.CHARCODE);
    没有用过。
    同意naxin(痴呆男人--我痴呆,我自豪!!) 的说法
      

  5.   

    说有response.setCharacterEncoding这个方法的到底有没有写过并运行过这行代码???"showmsg.jsp": Error #: 300 : method setCharacterEncoding(java.lang.String) not found in interface javax.servlet.http.HttpServletResponse
      

  6.   

    pigo说的对,根本就没有response.setCharacterEncoding()这个方法,
    只有request.setCharacterEncoding()这个方法!
      

  7.   

    request.setCharacterEncoding()是设置从request中取得的值或从数据库中取出的值
    response.setContentType("text/html;charset=gb2312")是设置页面中为中文编码
    前者是设置动态文字(参数,数据库),后者设置页面静态文字
      

  8.   

    誰说沒有response.setCharacterEncoding这个方法public abstract class BaseAction extends Action {
    protected Log log = LogFactory.getLog(this.getClass().getName());
    protected User oUser;
    protected Response oResponse;
    protected String params;
    protected XmlParse oXml=null;

    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form, 
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception{ response.setCharacterEncoding(HttpParams.getString(Constants.CHARCODE)); //$NON-NLS-1$

    if(!isLogin(request, response)){
    //return mapping.findForward("error.login.notlogin");
    return null;
    }

    params = request.getParameter(HttpParams.getString(Constants.PARAMS)); //$NON-NLS-1$

    if((params!=null)&&(!params.equalsIgnoreCase(""))){
    if(!initParam()){
    return null;
    }

    }
    return _execute(mapping, form, request, response, params);
    }我的代碼1直都正確
      

  9.   

    ServletResponse-----subClass--->HttpServletResponse,setCharacterEncoding這個方法在ServletResponse上
      

  10.   

    奇怪???我还是没有看到,我在Jbuilder里的代码提示也没有这个方法。
    ServletResponse的源代码如下(来自:D:\borland\JBuilderX\extras\jakarta-servletapi-4-src.zip\jakarta-servletapi-4-src\src\share\javax\servlet,我删除了注释信息,):
    package javax.servlet;import java.io.IOException;
    import java.io.PrintWriter;
    import java.io.UnsupportedEncodingException;
    import java.util.Locale; 
    public interface ServletResponse {    
        public String getCharacterEncoding();  
        
        public ServletOutputStream getOutputStream() throws IOException;
          
        public PrintWriter getWriter() throws IOException;
        
        public void setContentLength(int len);
      
        public void setContentType(String type);
        
        public void setBufferSize(int size);
        
     
        public int getBufferSize();
        
     
        public void flushBuffer() throws IOException;
            public void resetBuffer();
        
        public boolean isCommitted();
        
          public void reset();    
        
        public void setLocale(Locale loc); 
        
        public Locale getLocale();
    }
      

  11.   

    噢,找到了,是servlet2.4才新增加的方法,要Tomcat5以上才支持,现在我参与的很多项目开发的都还在用tomcat4:
        /**
         * Sets the character encoding (MIME charset) of the response
         * being sent to the client, for example, to UTF-8.
         * If the character encoding has already been set by
         * {@link #setContentType} or {@link #setLocale},
         * this method overrides it.
         * Calling {@link #setContentType} with the <code>String</code>
         * of <code>text/html</code> and calling
         * this method with the <code>String</code> of <code>UTF-8</code>
         * is equivalent with calling
         * <code>setContentType</code> with the <code>String</code> of
         * <code>text/html; charset=UTF-8</code>.
         * <p>This method can be called repeatedly to change the character
         * encoding.
         * This method has no effect if it is called after
         * <code>getWriter</code> has been
         * called or after the response has been committed.
         * <p>Containers must communicate the character encoding used for
         * the servlet response's writer to the client if the protocol
         * provides a way for doing so. In the case of HTTP, the character
         * encoding is communicated as part of the <code>Content-Type</code>
         * header for text media types. Note that the character encoding
         * cannot be communicated via HTTP headers if the servlet does not
         * specify a content type; however, it is still used to encode text
         * written via the servlet response's writer.
         *
         * @param charset  a String specifying only the character set
         *  defined by IANA Character Sets
         * (http://www.iana.org/assignments/character-sets)
         *
         * @see #setContentType
         *  #setLocale
         *
         * @since 2.4
         *
         */    public void setCharacterEncoding(String charset);
        
      

  12.   

    vfs:///zip:///[D:/Borland/JBuilder2005/thirdparty/jakarta-tomcat-5.0.27/webapps/tomcat-docs.war]/servletapi/javax/servlet/ServletResponse.html
      

  13.   

    response.setContentType指定 HTTP 响应的编码,同时指定了浏览器显示的编码.
    response.setCharacterEncoding设置HTTP 响应的编码,如果之前使用response.setContentType设置了编码格式,则使用response.setCharacterEncoding指定的编码格式覆盖之前的设置.与response.setContentType相同的是,调用此方法,必须在getWriter执行之前或者response被提交之前.
      

  14.   

    如果你request.setCharacterEncoding,对于post方式提交,就不需要使用了getBytes()进行提交信息的转码了.对于get方式的提交,如果是tomcat4,不需要使用了getBytes()进行提交信息的转码,但是对tocmat5,就需要由iso-8859-1转码到gb2312
      

  15.   

    真不好意思,这两天忙,没即使回帖.
    我正在看无废话xml,也要学习各位大虾的指点.
    谢谢.