一、通过配置文件组件
1.创建servlet
@WebServlet(urlPatterns = "/MyServlet")
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().println("汉字检测,english test");
//统一浏览器编码格式,不同浏览器因为初始编码格式不通用,所以用户使用时统一编码格式
resp.setContentType("text/html;character = utf-8");
resp.getWriter().flush();
resp.getWriter().close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
2.创建配置类文件systemconfig
@Configuration
public class SystemConfig {
@Bean
public FilterRegistrationBean characterEncodingFilterRegistrationBean(){
//创建字符编码过滤器
CharacterEncodingFilter characterEncodingFilt