I'm a little bit newbie using Java EE Filters and I have a doubt about them.
I want to create a Filter that do some stuff when every web page of my site (JSP) are loaded. For example, if I want to visit index.jsp, the Filter is loaded first and then index.jsp is loaded. The same for concact.jsp, sales.jsp, etc.
For that reason I decided to use this code in web.xml:
<filter-mapping>
<filter-name>MainFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
The problem is that the most of my JSPs include inside other auxiliary JSP like navigation bars, footer messages, etc. So, my index.jsp would be like this:
<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>
So, if I call index.jsp, the filter is called 4 times (1 for the index.jsp and 3 for the includes).
How could I fix this to call just once to the cookie filter? Any ideas? I'm getting mad with it...
Thanks!