This is almost identical to this question but the solution doesn't work for my servlet mapping.
Say I have a servlet which is mapped to /*
, therefore all requests are dispatched to that servlet. Now for certain requests I want to include a JSP page WEB-INF/mypage.jsp
.
The canonical solution is to use a RequestDispatcher
and include the JSP page:
@WebServlet(value = "/*")
public class MyServlet extends HttpServlet
{
private RequestDispatcher dispatcher_;
public void init() throws ServletException {
dispatcher_ = getServletContext().getRequestDispatcher("/WEB-INF/mypage.jsp");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// include the jsp page for some requests
dispatcher_.include(request, response);
}
}
Unfortunately since the mapping /*
has precedence over the mapping *.jsp
of the JSP servlet, the dispatch is routed to MyServlet
leading to an infinite recursion.
Note that this dispatch problem does not occur if the servlet would be mapped as default servlet (using mapping /
). Unfortunately I can't use the default servlet mapping in my special case.
So is there any other way to include a JSP page in a servlet mapped with /*
?