I have a servlet which acts as a front controller.
@WebServlet("/*")
However, this also handles CSS and image files. How can I prevent this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have 2 options:
Use a more specific URL pattern such as
/app/*or*.doand then let all your page requests match this URL pattern. See also Design Patterns web based applicationsThe same as 1, but you want to hide the servlet mapping from the request URL; you should then put all static resources in a common folder such as
/staticor/resourcesand create a filter which checks if the request URL doesn’t match it and then forward to the servlet. Here’s an example which assumes that your controller servlet is a@WebServlet("/app/*")and that the filter is a@WebFilter("/*")and that all your static resources are in/resourcesfolder.See also How to access static resources when mapping a global front controller servlet on /*.