Java 如何将 JSP 正确放置在 WEB-INF 文件夹中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4291545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to properly put JSPs in the WEB-INF folder?
提问by nayan
My question is how to put all the JSP files in WEB-INF/JSP/
in the proper manner?
我的问题是如何以WEB-INF/JSP/
正确的方式放置所有 JSP 文件?
Is there any configuration for this as the structure I'm aware of is:
是否有任何配置,因为我知道的结构是:
WEB-INF / JSP --> all jsp is reside in that folder
/ CLASSES -- all classes is reside that folder
/ LIB --> library file reside in that folder
How do I set this up properly according to the spec. Please help me with an answer for this.
我如何根据规范正确设置它。请帮我回答这个问题。
采纳答案by Teja Kantamneni
Its not a standard practice or valid as per the J2EE spec (I know using most of the java Web development frameworks like Struts, Spring MVC, Stripes you can do this). As per the spec, all our publicly accessibly pages should be out side of WEB-INF
. But if you want the pages to be in web-inf
, what you can do is to create a servlet along the lines of a controller servlet and forward the requests to jsp pages from your servlet and those pages can be in WEB-INF
, and there is no special configuration that can be done to do this.
根据 J2EE 规范,它不是标准实践或有效(我知道使用大多数 Java Web 开发框架,如 Struts、Spring MVC、Stripes,您可以做到这一点)。根据规范,我们所有可公开访问的页面都应该在WEB-INF
. 但是,如果您希望页面位于web-inf
,您可以做的是按照控制器 servlet 的行创建一个 servlet 并将请求从您的 servlet 转发到 jsp 页面,这些页面可以位于 中WEB-INF
,并且没有特殊的配置可以做到这一点。
回答by NAYAN RAMI
You can put your JSP in
你可以把你的JSP放进去
WEB-INF/jsp
folder and access that JSP using servlet.
文件夹并使用 servlet 访问该 JSP。
Create login.jspand then access that JSP using preloginservlet.java. This servlet redirects to login.jspwhich is in the WEB-INF/jsp
folder.
创建login.jsp,然后使用preloginservlet.java访问该 JSP 。此 servlet 重定向到文件夹中的login.jspWEB-INF/jsp
。
回答by Antaryami
You create a jsp page out side WEB-INF folder and inside that jsp use jsp:forward as
您在 WEB-INF 文件夹外创建一个 jsp 页面,并在该 jsp 内部使用 jsp:forward 作为
In web.xml file use give outside jsp name in welcome file list.
在 web.xml 文件中使用在欢迎文件列表中给出外部 jsp 名称。
It works for me...
这个对我有用...
回答by Abhijeet Ashok Muneshwar
Create an intermediary JSP outside of WEB-INF that includes your JSP.
在包含您的 JSP 的 WEB-INF 之外创建一个中间 JSP。
e.g. your page inside of WEB-INF is ProjectName/WEB-INF/JSP/yourPage2.jsp create a page ProjectName/yourPage1.jsp
例如,您在 WEB-INF 中的页面是 ProjectName/WEB-INF/JSP/yourPage2.jsp 创建一个页面 ProjectName/yourPage1.jsp
Write below code in yourPage1.jsp
在 yourPage1.jsp 中写入以下代码
yourPage1.jsp
yourPage1.jsp
<%@ include file="WEB-INF/JSP/yourPage2.jsp" %>