<% request.setCharacterEncoding("gb2312");%>这句话
是不是可以不用啊??

解决方案 »

  1.   

    <% request.setCharacterEncoding("gb2312");%>
    因为加上这句话,默认的提交是按utf-8编码的
      

  2.   

    加一句 meta
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      

  3.   

    会楼上的。
    我用的是tomcat5.0我知道问题的所在了:
    <?xml version='1.0' encoding="gb2312"?>
    <xsl:stylesheet version="1.0"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="html" version="1.0" encoding="gb2312" indent="yes"/><xsl:template match="/">
    <html>
    <head>
    <title>合同基本信息</title>
    </head>
    <body background="b.files/bj.gif" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
    <br></br>
        <div align="center"><h3>合同基本信息表</h3></div>
        <table width="100%" border="1" align="center" bordercolor="#336699">
          <tr bgcolor="#6699CC">
            <td align="center" width="75" height="16" ><font size="2">合同编号</font></td>
            <td align="center" width="80" height="16"><font size="2">合同签定日期</font></td>
            <td align="center" width="168" height="16"> <font size="2">签约单位</font></td>
            <td align="center" width="77" height="16"> <font size="2">总金额</font></td>
            <td align="center" width="77" height="16"> <font size="2">定金</font></td>
            <td align="center" width="77" height="16"> <font size="2">总运输费</font></td>
            <td align="center" width="77" height="16"> <font size="2">质保金</font></td>
            <td align="center" width="75" height="16"> <font size="2">支付方式</font></td>
            <td align="center" width="50" height="16"> <font size="2">签约人</font></td>
            <!--td align="center" width="80" height="16"> <font size="2">交货完成日期</font></td>
            <td align="center" width="80" height="16"> <font size="2">付款完成日期</font></td>
            <td align="center" width="80" height="16"> <font size="2">约定付款日期</font></td-->
         </tr>
        <xsl:for-each select="contract/contractinfo">
           <tr>
      <xsl:apply-templates select="contract_id"/>
    <xsl:apply-templates select="sign_date"/> 
    <xsl:apply-templates select="sign_company"/>
    <xsl:apply-templates select="total_money"/>
    <xsl:apply-templates select="jiao_money"/>
    <xsl:apply-templates select="total_send_charge"/>
    <xsl:apply-templates select="zhibao_money"/>
    <xsl:apply-templates select="pay_mode"/>
    <xsl:apply-templates select="sign_person"/>
        <!--xsl:apply-templates select="send_flag"/-->
        <!--xsl:apply-templates select="pay_flag"/-->
        <!--xsl:apply-templates select="prepay_flag"/-->
            </tr>
         </xsl:for-each>
       </table>
    <br></br>
    <br></br>
     
    </body>
    </html>
    </xsl:template> <xsl:template match="contract_id">
        <xsl:variable name="cid" select="."/>
      <td align="center" width="75" height="16">
    <font size="2">
      <a>
       <xsl:attribute name="href">ViewContract.jsp?type=3&amp;contract_id=<xsl:value-of select="$cid"/></xsl:attribute>
       <xsl:value-of select="$cid"/>
      </a>
    </font>
    </td>
    </xsl:template><xsl:template match="sign_date">
    <td align="center" width="80" height="16"><font size="2"><xsl:value-of select="."/></font></td>
    </xsl:template><xsl:template match="sign_company">
    <td align="center" width="168" height="16"><font size="2"><xsl:value-of select="."/></font></td>
    </xsl:template><xsl:template match="total_money">
    <td align="center" width="77" height="16"><font size="2"><xsl:value-of select="."/>元</font></td>
    </xsl:template><xsl:template match="jiao_money">
    <td align="center" width="77" height="16"><font size="2"><xsl:value-of select="."/>元</font></td>
    </xsl:template><xsl:template match="total_send_charge">
    <td align="center" width="77" height="16"> <font size="2"><xsl:value-of select="."/></font></td>
    </xsl:template><xsl:template match="zhibao_money">
    <td align="center" width="77" height="16"><font size="2"><xsl:value-of select="."/>元</font></td>
    </xsl:template><xsl:template match="pay_mode">
    <td align="center" width="75" height="16"><font size="2"><xsl:value-of select="."/></font></td>
    </xsl:template><!--xsl:template match="send_flag">
       <xsl:choose>
        <xsl:when test="boolean(.)">
            <td align="center" width="80" height="16"><font size="2"><xsl:value-of select="."/></font></td>
        </xsl:when>
        <xsl:otherwise>
            <td align="center" width="80" height="16"><font size="2"></font></td>
        </xsl:otherwise>
       </xsl:choose>
    </xsl:template><xsl:template match="pay_flag">
       <xsl:choose>
        <xsl:when test="boolean(.)">
            <td align="center" width="80" height="16"><font size="2"><xsl:value-of select="."/></font></td>
        </xsl:when>
        <xsl:otherwise>
            <td align="center" width="80" height="16"><font size="2"></font></td>
        </xsl:otherwise>
       </xsl:choose>
    </xsl:template><xsl:template match="prepay_flag">
       <xsl:choose>
        <xsl:when test="boolean(.)">
            <td align="center" width="80" height="16"><font size="2"><xsl:value-of select="."/></font></td>
        </xsl:when>
        <xsl:otherwise>
            <td align="center" width="80" height="16"><font size="2"></font></td>
        </xsl:otherwise>
       </xsl:choose>
    </xsl:template--><xsl:template match="sign_person">
    <td align="center" width="50" height="16"><font size="2"><xsl:value-of select="."/></font></td>
    </xsl:template></xsl:stylesheet> 使用它后生成的html是gb2312编码吧。好像是这里有问题
      

  4.   

    期望应该是这样的:http://localhost:8080/test/ViewContract.jsp?type=3&contract_id=订020现在是这样的:http://localhost:8080/test/ViewContract.jsp?type=3&contract_id=%E8%AE%A2020这是怎么回事啊
      

  5.   

    问题解决如下:test.jsp和test1.jsp问题中把test1.jsp换成<%@ page language="java"%>
    <%@ page contentType="text/html;charset=gb2312"%>
    <% request.setCharacterEncoding("GB2312"); %>
    <%
    String type=request.getParameter("type");
    String contract_id=new String(request.getParameter("contract_id").getBytes("ISO8859_1")); 
    %>
    <%=type%>
    <br/>
    <%=contract_id%>即可。
    xsl中只要把
    <xsl:output method="html" version="1.0" encoding="gb2312" indent="yes"/>改成
    <xsl:output method="xml" version="1.0" encoding="gb2312" indent="yes"/>
    就行。如果再不行就把 <xsl:attribute name="href">ViewContract.jsp?type=3&amp;contract_id=<xsl:value-of select="$cid"/></xsl:attribute>
    <xsl:value-of select="$cid"/>改成
     <xsl:attribute name="href">ViewContract.jsp?type=3&amp;contract_id=<xsl:value-of select="$cid"/></xsl:attribute>
    <!--xsl:attribute name="target">_blank</xsl:attribute-->
    <xsl:value-of select="$cid"/>
    哈哈。。终于成功了。
    给自己加分。
      

  6.   

    楼主,把分都给我 .我给你一个一劳永逸的方法Tomcat5中文问题解决之道 
    作者:mineral    来自:Jdon
    在tomcat5中发现了以前处理tomcat4的方法不能适用于处理直接通过url提交的请求,上网找资料终于发现了最完美的解决办法,不用每个地方都转换了,而且无论get,和post都正常。写了个文档,贴出来希望跟我有同样问题的人不再像我一样痛苦一次:-)问题描述:1 表单提交的数据,用request.getParameter(“xxx”)返回的字符串为乱码或者??
    2 直接通过url如http://localhost/a.jsp?name=中国,这样的get请求在服务端用request. getParameter(“name”)时返回的是乱码;按tomcat4的做法设置Filter也没有用或者用request.setCharacterEncoding("GBK");也不管用原因:1 tomcat的j2ee实现对表单提交即post方式提示时处理参数采用缺省的iso-8859-1来处理
    2 tomcat对get方式提交的请求对query-string 处理时采用了和post方法不一样的处理方式。(与tomcat4不一样,所以设置setCharacterEncoding(“gbk”))不起作用。解决办法:首先所有的jsp文件都加上:1 实现一个Filter.设置处理字符集为GBK。(在tomcat的webapps/servlet-examples目录有一个完整的例子。请参考web.xml和SetCharacterEncodingFilter的配置。) 1)只要把%TOMCAT安装目录%/ webapps\servlets-examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.class文件拷到你的webapp目录/filters下,如果没有filters目录,就创建一个。
    2)在你的web.xml里加入如下几行:    <filter>
            <filter-name>Set Character Encoding</filter-name>
            <filter-class>filters.SetCharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>GBK</param-value>
            </init-param>
        </filter>
            <filter-mapping>
            <filter-name>Set Character Encoding</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>3)完成.2 get方式的解决办法1) 打开tomcat的server.xml文件,找到区块,加入如下一行:URIEncoding=”GBK”完整的应如下:<Connector port="80"  maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" redirectPort="8443" acceptCount="100"
                   debug="0" connectionTimeout="20000"
                   disableUploadTimeout="true"
                   URIEncoding="GBK"/>2)重启tomcat,一切OK。执行如下jsp页页测试是否成功<%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.util.*"%>
    <%
            String q=request.getParameter("q");
            q = q == null? "没有值" : q;
    %>
    <HTML>
    <HEAD>
    <TITLE>新闻列表显示</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    <META http-equiv=pragma content=no-cache>
    <body>你提交了:<%=q%><br>
    <form action="tcnchar.jsp" method="post">
     输入中文:<input type="text" name="q"><input type="submit" value="确定"> <br>
    <a href="tcnchar.jsp?q=中国">通过get方式提交</a>
    </form>
    </BODY>
    </HTML>测试结果如果你输入文本框或者点超链都会显示:你提交了”中国”,说明成功!!!!!
      

  7.   

    修改tomcat/conf/server.xml
    <Connector acceptCount='100' connectionTimeout='20000' debug='0'
          disableUploadTimeout='true' enableLookups='false'
          maxSpareThreads='75' maxThreads='150' minSpareThreads='25'
          port='8080' redirectPort='8443' URIEncoding='GBK'/>
    加上:URIEncoding='GBK'即可。
    如果GBK不行,试一下ISO-8859-1最上面的filter还是要的
      

  8.   

    楼主问的是不是这个?
    在test1.jsp里加上
      byte a[]=contract_id.getBytes("ISO-8859-1"); 
      contract_id=new String(a);
    JSP接受的表单里如果有中文就得加上这一句。