自定义Filter禁止用户直接访问JSP页面
自定义Filter:
1 package gsxy.gswbm.util; 2 import java.io.IOException; 3 4 import javax.servlet.Filter; 5 import javax.servlet.FilterChain; 6 import javax.servlet.FilterConfig; 7 import javax.servlet.ServletException; 8 import javax.servlet.ServletRequest; 9 import javax.servlet.ServletResponse; 10 public class MyFilterJsp implements Filter{ 11 public void init(FilterConfig config) throws ServletException{} //初始化过滤器 12 public void destroy(){}//过滤器的生命周期结束 13 14 public void doFilter(ServletRequest request, ServletResponse response, FilterChain filter) 15 throws IOException, ServletException{ 16 request.getRequestDispatcher("/login.html").forward(request, response); 17 } 18 }
web.xml配置:
1 <filter> 2 <filter-name>MyFilterJsp</filter-name> 3 <filter-class>gsxy.gswbm.util.MyFilterJsp</filter-class> 4 </filter> 5 <filter-mapping> 6 <filter-name>MyFilterJsp</filter-name> 7 <url-pattern>*.jsp</url-pattern> 8 </filter-mapping>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。