在jsp页面中显示以中文命名的图片,总是显示一个红叉,上网搜了一下,是Tomcat的编码问题。下面是解决办法:
配置tomcat支持URL中文参数,只需添加Connector的URIEncoding参数即可,默认情况下该参数未被配置,默认用的是 ISO-8859-1,而一般浏览器默认用的发送编码为UTF-8,这样问题就出现了,
初步的解决方法如下:
修改Tomcat\conf下的server.xml
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
经测试,可以正常显示中文路径的资源。