0
我有点新手使用Java EE过滤器,我对他们有疑问。如何在包含页面中使用Java EE过滤器?
我想创建一个过滤器,当我的网站(JSP)的每个网页都加载时执行一些操作。例如,如果我想访问index.jsp,则首先加载过滤器,然后加载index.jsp。同为concact.jsp,sales.jsp等
出于这个原因,我决定在web.xml中使用此代码:
<filter-mapping>
<filter-name>MainFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
问题是最我的JSP中包括内的其他辅助JSP像导航栏,页脚信息,等等。所以,我的index.jsp会是这样:
<html>
<head>
...
</head>
<body>
<%@include file="/WEB-INF/includes/header.jsp"%>
<%@include file="/WEB-INF/includes/navbar.jsp"%>
// jsp/html/js stuff here...
<%@include file="/WEB-INF/includes/footer.jsp"%>
</body>
</html>
所以,如果我打电话的index.jsp,过滤器被称为4倍(1对包含index.jsp和3)。
我该如何解决这个问题,只需调用一次cookie过滤器?有任何想法吗?我生气了...
谢谢!
的可能的复制[?我可以排除一些具体网址从内部<滤波器映射>](https://stackoverflow.com/questions/ 3125296/can-i-exclude-some-concrete-url-pattern-inside-filter-mapping) –
vanje
感谢您的贡献。有时很难在搜索者中找到正确的主题:) – Ommadawn