我开发了一个部署到tomcat实例的应用程序,该实例也承载了其他应用程序。为此,端口80上的连接器将其URIEncoding设置为"UTF-8“。我希望找到一种为servlet重写此设置的方法,而无需在另一个端口上指定另一个连接器。我尝试使用tomcat过滤器设置过滤器如下:
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
final FilterChain filterChain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
filterChain.doFilter(request, response);
}但这改变不了什么。我的ISO-8859-1编码字符串在servlet中着陆时包含意想不到的字符。
发布于 2014-08-26 16:00:06
ServletRequest#setCharacterEncoding(String)方法仅设置用于请求主体的编码。您无法从Servlet中使用任何方法来声明请求URI的编码。这是servlet容器特定的。使用Tomcat,您需要在<Connector>级别进行操作。
在<Connector> for setCharacterEncoding中,总是可以使用setCharacterEncoding配置元素来执行您想做的事情。见here。
https://stackoverflow.com/questions/25510085
复制相似问题