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

下面这段代码输出的是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/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值