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代码
![](http://heisetoufa.iteye.com/images/icon_copy.gif)
![](http://heisetoufa.iteye.com/images/icon_star.png)
![](http://heisetoufa.iteye.com/images/spinner.gif)
<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>
其中<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/
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代码
![](http://heisetoufa.iteye.com/images/icon_copy.gif)
![](http://heisetoufa.iteye.com/images/icon_star.png)
![](http://heisetoufa.iteye.com/images/spinner.gif)
<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/
相关文章推荐
- 解决struts中<html:form>提交中文时乱码问题
- java 之Sting类型的List集合的汉字排序和String类型数组的汉字排序及List<Bean>排序
- Java读取TXT文件方法,和检索链接<a>[url]
- 存在bug<java.lang.NoSuchFieldException: DEFAULT_PARAM>
- java的web.xml中<url-pattern>配置
- JavaWeb 从init-param中读取多重数据(Enumeration<String>)
- <转>,防止刷新/后退引起的重复提交问题的Java Token代码,非Struts
- Java笔记6 网络编程<2>TCP、自定义图形界面浏览器、URL
- jsp js 函数 传参 只接受<%=request.getAttribute("name")%> 形式
- java的web.xml中<url-pattern>配置
- java的web.xml中<url-pattern>配置
- java的web.xml中<url-pattern>配置
- Java使用sql标签<sql:param />,<sql:param />设置日期参数
- <a href="<s:url action="navDel" ><s:param name="id" value="pid"/></s:url>"> 删除 </a>
- <转>防止刷新/后退引起的重复提交问题的Java Token代码,非Struts
- url 参数传递中文乱码问题 即<a href> 利用 js 的 encodeURI解决中文乱码问题
- 针对表单的get提交与超链接中<a></a>乱码问题
- java.lang.IllegalArgumentException: Invalid <url-pattern> toDo in 
- 使用struts2的<s:param>等标签向action传值出现中文乱码的解决方法
- JAVA基础(二) web.xml中<context-param>与<init-param>的区别与作用