Reputation: 16526
If I have a servlet I am able to forward to a jsp in the WebContent folder with no issues:
request.getRequestDispatcher("page.jsp").forward(request, response);
request being an HttpServletRequest and response being an HttpServletResponse.
Now for the question: What if I want to use package by feature? That is, move page.jsp into the same package as my servlet class so that all the files for one "feature" are in the same place. Is this possible?
Upvotes: 1
Views: 1317
Reputation: 13551
If you have a servlet class 'MyServlet 'in a package foo, then it would be available in WEB-INF/classes/foo/MyServlet. Now if you want to have JSP in the same package, you need to have the JSP in the folder /WEB-INF/classes/foo/page.jsp. Then you can forward to the JSP like,
request.getRequestDispatcher("/WEB-INF/classes/foo/page.jsp").forward(request, response);
Upvotes: 2
Reputation: 13771
JavaEE containers will not serve resources out of a jar. If you wanted to package by feature you'd have to pre-compile your JSPs and place them in the same package as other servlets for your feature. By supposing you did that, you wouldn't be able to serve any static resources from within the jar such as images, css or javascript.
If you really wanted to get fancy I suppose you could write a general purpose servlet that would serve resources from a jar. But I imagine that would get fairly complicated fairly quickly for little gain.
Upvotes: 0