I have a question I am struggling with. Just a hypothetical situation here. For example I have two folders jspPages1 and jspPages2. There are jsp pages I want to keep separated. I have one dispatcher servlet. And I want pages from the first folder to be mapped to “/public/jspNameFromFirstFolder.jsp” and from the second folder to “protected/jspNameFromSecondFolder.jsp”. Can I do that with one dispatcher servlet? If I try and make url patterns in web.xml to “/protected/’asteriks'” and “/public/’asteriks'”, what would @RequestMapping be like? Can you please clarify it for me? Thank you in advance.
Share
In my opinion, you shouldn’t expose your JSPs in the first place. After all, you want your user to access the page using the request mapping you provide. Your controller will then decide which view (in your case, they are JSP files) to present to the user.
What I usually do is to stuff the views under
WEB-INFdirectory to prevent users from guessing and accessing the JSP files directly. You can still keep the views separated if it helps you to organize your files. So, your directory structure may look like this:-This way, you can register your view folder to be
/WEB-INF/jsp/in Spring MVC.Your request mapping can be anything you want. It has nothing to do with your view directory structure.
For example:-