I would like to include a JSP page, but I would like .jsp to be inaccessible from the outside.
Put it in the /WEB-INF folder. The client cannot access it, but RequestDispatcher can access it.
request.getRequestDispatcher("/WEB-INF/page.jsp").forward(request, response);
Also, how can I pass a model object to it.
Set it as a request attribute.
request.setAttribute("bean", bean); // It'll be available as ${bean} in JSP.
See also:
- Servlet tag details page (contains a Hello World example and useful links)
- Hidden JSP / Servlet Functions
- Web Application Template Design
However, keep in mind that mapping a servlet to / takes on the execution of the servletcontainer builtin DefaultServlet function to serve static content. You will have to process all static files such as JS / CSS / images. Consider choosing a more specific url-pattern as /pages/* or *.do for JSP views. Bring in the end Filter in front, as described in this answer .
Balusc
source share