您的位置:首页 > 编程语言 > Java开发

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

2013-03-31 12:48 148 查看
下面这段代码输出的是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代码







<body>
<c:urlvalue="http://localhost:8080/news/HelloServlet"var="url">
<c:paramname="hello"value="${hello}"/>
<c:paramname="test"value="${hello}"/>
</c:url>
<ahref="<c:out
value="${url}"/>">${hello}</a>
</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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐