开发者

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

开发者 https://www.devze.com 2023-01-27 18:09 出处:网络
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:

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. Pleas开发者_开发知识库e help me with an answer for this.


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.


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.


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" %>  


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消