java 把url传参的汉字变成%百分号形式,<c:url><c:param>,url提交汉字乱码

来源:互联网 发布:执业药师网络报名机构 编辑:程序博客网 时间:2024/06/16 01:00
下面这段代码输出的是url为

http://localhost:8080/news/HelloServlet?hello=%e5%a4%a7%e5%ae%b6%e5%a5%bd&test=%e5%a4%a7%e5%ae%b6%e5%a5%bd

Html代码 复制代码 收藏代码
  1. <body>
  2. <c:urlvalue="http://localhost:8080/news/HelloServlet"var="url">
  3. <c:paramname="hello"value="${hello}"/>
  4. <c:paramname="test"value="${hello}"/>
  5. </c:url>
  6. <ahref="<c:out value="${url}"/>">${hello}</a>
  7. </body>
<body>  <c:url value="http://localhost:8080/news/HelloServlet" var="url">    <c:param name="hello" value="${hello}" />    <c:param name="test" value="${hello}" />  </c:url>  <a href="<c:out value="${url}" />">${hello}</a></body>


其中<c:url value="http://localhost:8080/news/HelloServlet" var="url">
中的value为提交的url,var表示为url
<c:param name="hello" value="${hello}" />中的name为在下边引用的名字,如${hello},value为静态值,即显示的是${hello}中的hello,但会被转化为%百分号形式,避免url提交汉字出现乱码

这个设置还需要设置tomcat/conf/server.xml中的URLEncoder="urf-8"
 
 
除了用上面的方法消除乱码,也可用下面的方法:
 
pageActionSearch.action?resourcesName=<%=java.net.URLEncoder.encode("模具","UTF-8")%>

黑色头发:http://heisetoufa.iteye.com/
原创粉丝点击