浏览器中文乱码
老师好,如下代码在浏览器中文乱码,idea file encoding设置都是 utf-8,idea清除缓存,都尝试了还是没效果?
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> no 哈哈 123 <h4>你好啊123</h4> </body> </html>
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <filter> <filter-name>firstFilter</filter-name> <filter-class>com.imooc.filter.FirstFilter</filter-class> </filter> <filter-mapping> <filter-name>firstFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
package com.imooc.filter; import javax.servlet.*; import java.io.IOException; public class FirstFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { System.out.println("FirstFilter已被初始化"); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { response.setContentType("text/html;charset=utf-8"); System.out.println("过滤器已生效"); chain.doFilter(request,response); // response.getWriter().println("<p style='color:red'>过滤器已生效向浏览器输出</p>"); } @Override public void destroy() { System.out.println("FirstFilter已被销毁"); } }
源自:过滤器
1-3 开发第一个过滤器
13
收起
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星