web 3.0 怎么添加过滤网页
怎么设置过滤网页?
怎么设置过滤网页?
2016-05-06
现在servlet3.0都已经支持注解了,过滤器可以丝毫不用在web.xml里面配置,直接添加过滤器。
package com.cisdimes.servlets; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.annotation.WebFilter; @WebFilter(urlPatterns={"/*"}) public class SystemFilter implements Filter { @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("开始过滤处理"); chain.doFilter(request, response); return; } @Override public void init(FilterConfig arg0) throws ServletException { System.out.println("开始过滤器初始化"); } }
这是web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>dynamicwebapp</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
想要过滤网页,应该是修改过滤规则为*.jsp或者*.html看你用的网页是什么,jsp就是前者,html就是后者
举报