I am developing a web application using JSP and servlets.
I developed a servlet filter goal for Login . Which checks if the user is logged in or not, if the user is logged in, he allows access to the requested resource, otherwise he redirects the request to the Login page . And it works great.
Filter
public class MyFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
web.xml
<filter> <filter-name>MyFilter</filter-name> <filter-class>com.myfilter.MyFilter</filter-class> <init-param> <param-name>PARAM_NAME_HERE</param-name> <param-value>PARAM_VALUES_HERE</param-value> </init-param> </filter> <filter-mapping> <filter-name>MyFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Now I have deployed this application with the name Login on Tomcat 7 . This servlet filter works great for resources (JSP, Servltes, .css, .js) in this web application.
So, Tomcat now has other web applications like Profiles , Distribution , etc. So now I want to apply the Filter application in Login . Applicable to all other applications deployed to Tomcat . Means that each request to other application resources must go through the Filter that I developed.
Therefore, any suggestions will be appreciated!
Edit1
I do not want to put the package containing Filter in other applications. Because there are more than 10 applications deployed on the Tomcat server, and some of them will be deployed. Therefore, suppose that if I put the package containing Filter in all other applications and bind the servlets, but if a few days after I want to make some changes to the Filter, I will need to make changes to all applications and redistribute them will be necessary.