How to properly put JSPs in the WEB-INF folder?

2019-01-14 04:56发布

My question is how to put all the JSP files in WEB-INF/JSP/ in the proper manner?

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.

4条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-14 04:59

Create an intermediary JSP outside of WEB-INF that includes your JSP.

e.g. your page inside of WEB-INF is ProjectName/WEB-INF/JSP/yourPage2.jsp create a page ProjectName/yourPage1.jsp

Write below code in yourPage1.jsp

yourPage1.jsp

<%@ include file="WEB-INF/JSP/yourPage2.jsp" %>  
查看更多
劫难
3楼-- · 2019-01-14 05:14

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.

查看更多
做自己的国王
4楼-- · 2019-01-14 05:14

You can put your JSP in

WEB-INF/jsp 

folder and access that JSP using servlet.

Create login.jsp and then access that JSP using preloginservlet.java. This servlet redirects to login.jsp which is in the WEB-INF/jsp folder.

查看更多
唯我独甜
5楼-- · 2019-01-14 05:18

You create a jsp page out side WEB-INF folder and inside that jsp use jsp:forward as

In web.xml file use give outside jsp name in welcome file list.

It works for me...

查看更多
登录 后发表回答