window.open("/stms/aboutGrant.jsp?grantCode="+ code+"&grantName="+ encodeURIComponent(name),"aboutGrant","width=500,height=200,status=yes,resizable=no,top=280,left=300");
像这种jsp转jsp传值 用${param.grantName}得到的是乱码;
还有<a href="/stms/uploadCommand.do downFile=_&fileCode=0&TemplatefileName=${grantInfo.feasible_template}"target="frameDownLoad"><img src="/stmsres/images/index/ico_outline.gif" width="16" height="16" /></a>
还有这种jsp转java传值并且${grantInfo.feasible_template}是已经进行了java.net.URLEncoder.encode编码的字符串,但是传到后台一样的出现了乱码,tomcat,jsp,java都设置了编码格式为utf-8,求高手解答。jspjavatomcat

解决方案 »

  1.   

    在你接受的地方还要进行java转码:
    String deName = java.net.URLEncoder.decoder(request.getParameter("name"));
      

  2.   

    转了, 传过去时是%99%E8%82%B2%E9%A1%B9%E7%9B%AE%29.doc这样的 但是到后台获得的时候就变项目详细报告提纲(继续医学教育项目).doc这样了。用decoder转码根本就没用
      

  3.   

    全部都改回GBK去,Utf-8不行,具体的原因我就不说了,说来话长
      

  4.   

    参数=new String(参数.getBytes("gbk"),"utf-8");
      

  5.   

    回复于: 2013-03-01 11:57:38 
    参数=new String(参数.getBytes("gbk"),"utf-8"); 回复于: 2013-03-01 11:57:38 
    参数=new String(参数.getBytes("gbk"),"utf-8"); 
      

  6.   

    在tomcat中修改server如下:
    <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000" 
                   redirectPort="8443" URIEncoding="UTF-8"/>
    URIEncoding="UTF-8"就支持url传中文了
      

  7.   

    以上所有方法都不行,已经试过了。tomcat,jsp,java我的都是utf-8的,我产生乱码的原因是传输的过程中乱码就产生了,后台request.getParameter("name")取得的就已经是乱码,主意是乱码不是编码。所有对乱码进行操作是没有用的, 我要找的方法是避免传输过程中乱码的产生。 
      

  8.   

    web.xml中添加Filter:
    org.springframework.web.filter.CharacterEncodingFilter
    初始化为UTF-8
      

  9.   

    问题令我不解的是我这个值开始是从后台传过来的,已经经过了java.net.URLEncoder.encode的编码,传到界面是类似%A的形式的,但是我把这个值放到链接后面传到后台用request得到的就是乱码。
      

  10.   

    当你用ruques接受到超链接上的参数以后,有没有进行再次的解码?比如可以这样   //编码
       //在弄超链接时可以这样
       <a href=".....?name=<%RULEncoder.encode("中国","UTF-8")%>">  //解码
      String name=requst.getParameter("name");
      //此时应该是乱码
      String name1=new String(name.getBytes[],"UTF-8");
      //这个步骤过后,name1应该可以解码成你编码之前要传输的值了,当然utf-8这个是我编码时的格式,你根据你的编码替换掉
    );
      

  11.   

    通过URL方式传值中文到后台,要用js进行两次转码,
    var param = “中文”;
    param = URLencode(URLencode(param));
    再传到后台。
    用encodeURL解码就OK
      

  12.   

    http://localhost:81/stms/uploadCommand.do?downFile=_&fileCode=0&TemplatefileName=%E9%A1%B9%E7%9B%AE%E8%AF%A6%E7%BB%86%E6%8A%A5%E5%91%8A%E6%8F%90%E7%BA%B2%28%E7%BB%A7%E7%BB%AD%E5%8C%BB%E5%AD%A6%E6%95%99%E8%82%B2%E9%A1%B9%E7%9B%AE%29.doc
    不行啊! 我的链接是上面的样子,但是我用request得到它就是乱码,如果是写在JS中的话可以用encodeURIComponent对TemplatefileName参数进行处理那么得到的就不是乱码,但是我要用在html中
      

  13.   

    是否有具体的代码,说实话这些方法我都已经试过了,我代码的具体使用情况如下
    <c:forEach items="${grantInfoList}" var="grantInfo">
    <c:choose>
    <c:when test="${grantInfo.feasible_template!=null}">
    <a  href="/stms/uploadCommand.do downFile=_&fileCode=0&TemplatefileName=${grantInfo.feasible_template}" target="frameDownLoad"><img src="/stmsres/images/index/ico_outline.gif" width="16" height="16" />
    </a>
    </c:when>
    <c:otherwise>--</c:otherwise>
    </c:choose>
    </c:forEach>此值${grantInfo.feasible_template}我是已经在后台进行过编码传过来的。后台接收fileName = URLDecoder.decode(request.getParameter("TemplatefileName"),"utf-8");
    如果有好的方法,请写一下代码,感激不尽。
      

  14.   

    我之前也遇到了这种情况,就没有用它那个转码了,自己写的
    function encodeURIStr(str){ 
        str = str.replace(/:/g, '%3A'); 
        str = str.replace(/@/g, '%40'); 
        str = str.replace(/&/g, '%26'); 
        str = str.replace(/=/g, '%3D'); 
        str = str.replace(/#/g, '%23'); 
        str = str.replace(/\+/g, '%2B'); 
        return str; 
    }