标签:rri ora 直接 生活 outline xhtml help port content
Servlet过滤器从字面上的字意理解为景观一层次的过滤处理才达到使用的要求,而其实Servlet过滤器就是服务器与客户端请求与响应的中间层组件,在实际项目开发中Servlet过滤器主要用于对浏览器的请求进行过滤处理,将过滤后的请求再转给下一个资源。
过滤器的基本概念
public class EncodingFilter implements Filter { @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub HttpServletRequest request=(HttpServletRequest)req; HttpServletResponse response=(HttpServletResponse)resp; request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); chain.doFilter(req, resp); } @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } }
XML文件
<filter> <filter-name>EncodingFilter</filter-name> <filter-class>pers.filter.EncodingFilter</filter-class> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
定义一过滤器,实现Filtter接口
web.xml文件中,配置过滤器
标签:rri ora 直接 生活 outline xhtml help port content
原文地址:https://www.cnblogs.com/yangss-myblog/p/10742124.html