使用encodeURIComponent编码
decodeURIComponent已编码
function encodeURIComponent(encodedURIString : String) : String

解决方案 »

  1.   

    你的设计有问题,地址是有限制的,255字节,超过会报错,而你的代码要把textarea的内容放到地址栏上,字符少没问题,你怎么保证用户不在上面多输?!!!
      

  2.   

    你应该用 <form name="form1" method=post>
      

  3.   

    我这是个例子了,其实我是用的是ajax,它用的是get方法。所以有这个问题。
      

  4.   

    var kv = escape(document.all.form1.fm.value);
      

  5.   

    我用escape编码后,在jsp端没接收到值.
    jsp 页面:
    <%@ page contentType="text/html; charset=GBK" %>
    <% request.setCharacterEncoding("GBK"); %>
    <%
      String sm=request.getParameter("fm");
      String act=request.getParameter("action");  System.out.println("fm: "+sm);
      System.out.println("action: "+act);
    %>获取的值:${param.fm}
    获取的值:${param.action}c.htm:
    <script language="javascript">
        function dock(){
         var kv=escape(document.all.form1.fm.value);
         window.location='http://localhost:8080/trasp/so.jsp?action=中文&fm='+kv;
        }
      </script>  <form name="form1">
         <textarea name="fm" cols="20" rows="10">
            a
            b
            c(这三个a,b,c中间是有换行的。)
         </textarea>
       <input type="button" value="dolocation" onclick="dock();">
      </form>如果我用encodeURIComponent 编码,但是这个会用UTF-8来编码,我又需把
    <%@ page contentType="text/html; charset=GBK" %>
    <% request.setCharacterEncoding("GBK"); %>
    改成
    <%@ page contentType="text/html; charset=UTF-8" %>
    <% request.setCharacterEncoding("UTF-8"); %>
    但是改了以后这个action的中文值就得不到了,我不想用UTF-8编码,我只想把换行符传过去,我该怎样办呢?
      

  6.   

    把escape换成encodeURIComponent试试,
    前段时间也发了个贴,
    不知道为什么用esape服务端就接收不到数据,结果也没有弄明白是为什么。
      

  7.   

    转换时
    escape 按unicode编码
    encodeURIComponent 按utf-8编码在服务器端,如果系统不能替你转换,你需要自行转换
      

  8.   

    xuzuning(唠叨) :我之前也发过一个有关escape的问题,它会导致request得不到内容.
    以下是前段时间为这个问题发的个贴子.http://community.csdn.net/Expert/topic/4583/4583452.xml?temp=.7443659
    汉字escape后,request不成功
      

  9.   

    最后还是把\n转换成<br>
       public static String replaceBr(String str){
           String retStr="";
               if(str!=null){
             retStr=replace(replace(str,"\r\n","<br>")," ","&nbsp;");
               }
               System.out.println("end:"+retStr);
           return retStr;
       }