url地址中文传输问题
请求地址:
http://localhost:8888/index.jsp?s=%E6%96%97%E5%9C%B0%E4%B8%BB&nau=http://xxxx/file/gd/2010-09/02/4004320.apk%3Fid=3463%26wf=0,2%26softName=%E6%96%97%E5%9C%B0%E4%B8%BB%26pstyle=s

index.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="java.util.regex.Pattern" %>
<%@ page import="java.util.regex.Matcher" %>

<%
    /*<Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8"
               connectionTimeout="20000"
               redirectPort="8443" />
      特别引起我注意的是 URIEncoding="UTF-8" ,如果不设置,url上传递的中文就不能被正确解码    
    */

    //http://localhost:8888/index.jsp?s=%E6%96%97%E5%9C%B0%E4%B8%BB&nau=http://xxxx/file/gd/2010-09/02/4004320.apk%3Fid=3463%26wf=0,2%26softName=%E6%96%97%E5%9C%B0%E4%B8%BB%26pstyle=s

    String s = request.getParameter("s");
    String str = request.getParameter("nau");

    //out.println(URLDecoder.decode(s,"UTF-8"));  
    out.println(str+"<br/>");

    Pattern p = Pattern.compile("softName=(.*)[&$]");
    Matcher m = p.matcher(str);
    String softName = "";
    while(m.find()){

       softName =  m.group(1);
       out.println("softName=" + softName);
        
    }

   // out.println("decode:"+URLEncoder.encode(softName,"UTF-8"));

    out.println(str.replace(softName,URLEncoder.encode(softName,"UTF-8")));

    //out.println(s);
    //str = URLDecoder.decode(str,"UTF-8");
    //out.println("test="+str);



%>


lunzi   2010-09-02 23:03:35 评论:0   阅读:853   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog