不同路径解析器
我有一个正在困扰的问题。这里只是假设的情况。例如我有两个文件夹 jspPages1 和 jspPages2。我想将一些 jsp 页面分开。我有一个调度程序 servlet。我希望第一个文件夹中的页面映射到“/public/jspNameFromFirstFolder.jsp”,第二个文件夹中的页面映射到“protected/jspNameFromSecondFolder.jsp”。我可以使用一个调度程序 servlet 来完成此操作吗?如果我尝试将 web.xml 中的 url 模式设置为“/protected/'asteriks'”和“/public/'asteriks'”,@RequestMapping 会是什么样子?你能为我澄清一下吗?先感谢您。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您一开始就不应该暴露您的 JSP。毕竟,您希望用户使用您提供的请求映射来访问页面。然后,您的控制器将决定向用户呈现哪个视图(在您的情况下,它们是 JSP 文件)。
我通常的做法是将视图塞到
WEB-INF
目录下,以防止用户猜测并直接访问JSP文件。如果有助于您组织文件,您仍然可以将视图分开。因此,您的目录结构可能如下所示: -这样,您就可以在 Spring MVC 中将视图文件夹注册为
/WEB-INF/jsp/
。您的请求映射可以是您想要的任何内容。它与您的视图目录结构无关。
例如:-
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-INF
directory 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:-