nayan
nayan

Reputation: 149

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

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.

Upvotes: 10

Views: 31810

Answers (4)

NAYAN RAMI
NAYAN RAMI

Reputation: 365

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.

Upvotes: 10

Abhijeet Ashok Muneshwar
Abhijeet Ashok Muneshwar

Reputation: 2508

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

Upvotes: 4

Antaryami
Antaryami

Reputation: 11

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

Upvotes: 1

Teja Kantamneni
Teja Kantamneni

Reputation: 17472

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.

Upvotes: 9

Related Questions