頁面訪問被攔截,j2ee中如何攔截jsp頁面?

 2023-11-22 阅读 25 评论 0

摘要:2019獨角獸企業重金招聘Python工程師標準>>> 加filter: public class RightFilter implements Filter {public void init(FilterConfig filterConfig) throws ServletException {}public void doFilter(ServletRequest servletRequest, ServletResponse serv

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

加filter:

public class RightFilter implements Filter {public void init(FilterConfig filterConfig) throws ServletException {}public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;User user = (User) httpServletRequest.getSession(true).getAttribute("user");if (!isExcludePages(httpServletRequest.getRequestURI())) {if (user == null) {httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/login.jsp");return;}}filterChain.doFilter(servletRequest, servletResponse);}private boolean isExcludePages(String url) {return url.indexOf("login.dhtml") != -1|| url.indexOf("logout.dhtml") != -1|| url.indexOf("login.jsp") != -1|| url.endsWith(".css")|| url.endsWith(".js")|| url.endsWith(".gif")|| url.endsWith(".jpg")|| url.endsWith(".png");}public void destroy() {}
}

需要在web.xml里面配置一下:

<filter><filter-name>rightFilter</filter-name> <filter-class>com.xxx.filter.RightFilter</filter-class> </filter><filter-mapping><filter-name>rightFilter</filter-name><url-pattern>*.dhtml</url-pattern></filter-mapping>

頁面訪問被攔截。?

轉載于:https://my.oschina.net/u/1260221/blog/421898

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/184843.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息