08-08
27
url中文编码转换
作者:Java伴侣 日期:2008-08-27
复制内容到剪贴板 程序代码
<%@page import="java.net.URLEncoder,java.net.URLDecoder" %>
<%
String str2=URLEncoder.encode("中文测试","UTF-8");
request.setCharacterEncoding("utf-8"); //must setCharacterEncoding
String str=null;
if(request.getParameter("para")!=null)
{
str=request.getParameter("para");
str=URLDecoder.decode(str,"UTF-8");
}
%>
<%=str%>
<a href="test.jsp?para=<%=str2%>">test</a>
<%
String str2=URLEncoder.encode("中文测试","UTF-8");
request.setCharacterEncoding("utf-8"); //must setCharacterEncoding
String str=null;
if(request.getParameter("para")!=null)
{
str=request.getParameter("para");
str=URLDecoder.decode(str,"UTF-8");
}
%>
<%=str%>
<a href="test.jsp?para=<%=str2%>">test</a>
评论: 0 | 引用: 0 | 查看次数: 1480
发表评论