标签:
1.java类进行编码
a.jsp
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.URLDecoder"%>
<% staticListUrl = "b.jsp?lpath="+URLEncoder.encode(URLEncoder.encode("博客园","utf-8"),"utf-8"); %> <a href="<%=staticListUrl%>">点击</a>
//用java.net.URLEncoder.encode(...)方法就行两次编码,跳转到b.jsp页面,b.jsp页面接受到参数后,用java.net.URLDecoder.decode(...)进行一次解码即可!
//谨记是二次编码一次解码!
b.jsp
<%
String lpath = request.getParameter("lpath")!=null?URLDecoder.decode(request.getParameter("lpath"),"utf-8"):"";
System.out.print(lpath);
%
博客园
2.用js的encodeURI的进行编码
<script>
function search()
{
var lpath = $(".keyword").val();
if(lpath!=""&&lpath!=null){
window.location.href = "b.jsp?lpath="+encodeURI(encodeURI(keyword,"utf-8"),"utf-8");
}
}
</script>
<input type="hidden" name="hidden" class="keyword" value="<%=keyword%>"/>
<input type="button" onclick="search();" value="搜索"/>
//如果用js的encodeURI(...)进行编码后,跳到了一个jsp页面,则这个页面接受中文参数后用java.net.URLDecoder.decode(...)进行解码即可,如果还是传到了一个js中处理的话,那就要用的js的decodeURI(URIstring)进行解码!同样的都是 二次编码一次解码!
标签:
原文地址:http://www.cnblogs.com/mashiyuan/p/4241733.html