How to put jsp files in a separate folder?
jsp
Solution
As part of web applications we should maintain a standard folder structure. i.e ProjectFolder then inside WEB-INF folder which consists the web.xml file should be there.
We can keep jsp files any where in the project Directory. Based on that we should form URL.
Ex: I have project "Demo" and Inside "WEB-INF" is available and WEB-INF contains web.xml file. I have placed my jsp files ex: jsp1,jsp2,jsp3.. directly inside the "Demo" folder
So i should access these jsp's using following URL.
[ex: http://localhost:8080//Demo/jsp1.jsp]
Scenario 2: I have placed my jsp files ex: jsp1,jsp2,jsp3.. inside "myjsp" folder. now i placed "myjsp" folder directly inside the the "Demo" folder.
So i should access these jsp's using following URL. Note:- I am using Tomcat server with 8000 as port number.
[ex: http://localhost:8080//Demo/myjsp/jsp1.jsp]
Conclusion:
- If we place the jsp files outside the WEB-INF folder in project directory then we able to access those jsp's or net resources directly by forming the URL. Here we no need to configure anything in the configuration file in web.xml
- If we want to place the jsp's inside the WEB-INF folder, then we should configure the web.xml to access those jsps. ex:
Scenario 3: I have placed my jsp files ex: jsp1,jsp2,jsp3.. inside "myjsp" folder. now i placed "myjsp" folder inside the the "WEB-INF" folder.
Now we will not able access these jsp pages directly, Since WEB-INF directory is private directory. we need to configure the web.xml as shown below.
<web-app>
<servlet>
<servlet-name>jsp1</servlet-name>
<jsp-file>/WEB-INF/myjsp/jsp1.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>jsp1</servlet-name>
<url-pattern>/jsp1</url-pattern>
</servlet-mapping>
</web-app>
So we should access these jsp's using following URL.
[ex: http://localhost:8080/Demo/jsp1]
Here my serverurl= localhost and port number=8080
Problem
When I had 7 jsp pages under web-content, it was working fine, but when I am putting all the jsp files under a folder named "jsp" in web-content, my browser is unable to find the pages. I have tried just by changing the path in web.xml. Any help would be appreciated. Should I use jsp:include