0

I am experimenting with Servlet+JSP MVC model, but can't understand where I am wrong.

My first try is a "catch-all" @WebServlet which should act as a "router" for all requests:

@WebServlet( urlPatterns = {"/*"} )
public class RoutingServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        System.out.println(req.getPathInfo());      
        req.getRequestDispatcher("index.jsp").forward(req, res);
    }
}

This gives me a StackOverflowError.

How can I make the servlet "exclude" .jsp from its catch-all ?

Fabio B.
  • 9,138
  • 25
  • 105
  • 177

1 Answers1

1

Usually you don't want /* mappings on a servlet - just a filter. '/*' pattern is going to send everything to your servlet. I would suggest you define something like *.html (a logical mapping) as your mapping and then forward to jsps housed inside WEB-INF.

Brian
  • 13,412
  • 10
  • 56
  • 82
  • 1
    A great summary of URL pattern use cases: http://stackoverflow.com/questions/4140448/difference-between-and-in-servlet-mapping-url-pattern – Brian Feb 29 '16 at 15:59