0

I have a jsp located in the /package directory.

Then I map my servlet with a WebServlet Annotation of "/package/*".

In my servlet, I forward the request to a jsp in the above directory:

        RequestDispatcher dispatcher = 
                request.getServletContext().getRequestDispatcher("/package/some_file.jsp");
        dispatcher.forward(request, response); 

This causes a StackOverflowError:

org.apache.catalina.core.ApplicationDispatcher.invoke Servlet.service() for servlet SomeServlet threw exception

I can easily fix this by changing the name of the jsp folder to something else (eg: package_files). But I don't understand why this is necessary because I thought the servlets and the jsp folders were in entirely different locations (specifically, the servlet is in /web/WEB-INF/classes/package while the jsp is in /web/package.

Am I mistaken, or is there something wrong with my setup?

Thank you.

theyuv
  • 1,556
  • 4
  • 26
  • 55
  • 1
    Are you saying that you expected that `@WebServlet("/package/*")` is referring to `/web/WEB-INF/classes/package`? Where exactly did you learn that? The official tutorial and documentation just say that `@WebServlet` value represents the web path (URL pattern) not the class path (file system location). – BalusC Jul 18 '17 at 18:07
  • I see, so is it recommended not to have URL patterns and root folders be of the same name? – theyuv Jul 18 '17 at 18:44
  • ...because then you cannot match servlets with a wildcard at the end without also matching the contents of the folder in the root directory. – theyuv Jul 18 '17 at 19:05

0 Answers0