I have a jsp page called home.jsp
outside the WEB-INF directory and an other jsp
page called service.jsp
inside the WEB-INF
folder. I need to put this service.jsp
page inside the WEB-INF
directory so it cannot be accessible if a user attempts to get access to it by typing its URL. So my problem is how can i navigate from home.jsp
to service.jsp
with click on button in the home.jsp
Thank you.
Asked
Active
Viewed 8,140 times
1

Vincent Ramdhanie
- 102,349
- 23
- 137
- 192

Anis Bedhiafi
- 185
- 1
- 5
- 22
-
If you put home.jsp as well in WEB-INF folder that whats the problem here? – Abhishek Suthar Nov 27 '13 at 20:24
-
if i put home.jsp inside web-inf as well i get an http error saying Problem accessing /service.jsp while calling service.jsp with this line in home.jsp – Anis Bedhiafi Nov 27 '13 at 20:31
-
your page is demo/WEB-INF/pages/yourPage.jsp create a page demo/yourPage.jsp Source Code: view plainprint? Note: Text content in the code blocks is automatically word-wrapped <%@ include file="WEB-INF/pages/yourPage.jsp" %> – Abhishek Suthar Nov 27 '13 at 20:46
-
So, you want to access to a JSP that you deliberately put inside WEB-INF to make it inaccessible? Isn't it quite contradictory? – JB Nizet Nov 27 '13 at 21:09
2 Answers
0
You should use forward to access the file under WEB-INF. There are two methods for you to choose: 1.look like this :
<!-- /test/test2.jsp outside WEB-INF -->
<html>
<body>
<form name="testform">
<jsp:forward page = "/WEB-INF/jsp/test/test.jsp" />
</form>
</body>
</html>
2.use struts to forward
<action path="/test" type=" test.TestAction" scope="request">
<forward name="test" path="/WEB-INF/jsp/test/test.jsp"/>
</action>

Dean Winchester
- 1
- 1
0
why is it contradictory ? i want my application to access to that file and keep it away from reach by typing a simple URL.
I finally found what i have to do.
I created a servlet let's say serviceServlet.java in which i include this line in the doGet() method:
this.getServletContext().getRequestDispatcher("/WEB INF/service.jsp").forward(req, resp);
This line will forward my request to the service.jsp file under WEB-INF.
Next step i defined in my web.xml a url pattern to redirect to that servlet when clicking a button say /service like this
<servlet>
<servlet-name>serviceServlet</servlet-name>
<servlet-class>mypackage.CloudUploadserviceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>serviceServlet</servlet-name>
<url-pattern>/service</url-pattern>
</servlet-mapping>
And ultimately in the home.jsp file i included this line in the onClick method to call the servlet:
onclick="location.href='/service'"
And it's done :)

Anis Bedhiafi
- 185
- 1
- 5
- 22