Use a servlet filter instead.
Here's a basic kickoff example:
@WebFilter("*.html5")
public class MyFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
// Perform here some code before processing the request.
// ...
chain.doFilter(req, res);
// Perform here some code after processing the request.
// ...
}
}