三步骤:
一、在tomcat的安装目录下的conf/server.xml中,大概50行左右:进行如下修改
(红色的加为的配置信息)
<Connector port="8088" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
二、加入一个实现了javax.servlet.Filter接口的类
并重写其doFilter方法:
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
chain.doFilter(request, response);
}
三、在web.xml中使用其过滤器
<filter>
<filter-name>characterfilter</filter-name>
<filter-class>com.huicer.demo.filter.CharacterFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>characterfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
结束,那么无论其用户名、密码都可为中文了。