request对象

2016-08-04  本文已影响0人  Mier911

request 接收中文参数时要设置编码格式为utf-8:

<%request.setCharacterEncoding("UTF-8");%>

<%=request.getParameter("username")%>

URL 在页面中直接传递参数中文参数会造成乱码的问题,并且无法解决

href="request.jsp?username=李四"

除非修改 Tomcat 配置文件:

在Tomcat 安装目录下的 conf/server.xml  ,添加 URIEncoding="utf-8"

<Connectorport="8080"protocol="HTTP/1.1"connectionTimeout="20000" redirectPort="8443" URIEncoding="utf-8"/>

(不能直接在Eclipse 项目列表里面修改 Servers下的 server.xml文件,修改无效)

上一篇 下一篇

猜你喜欢

热点阅读