How to navigate between jsp pages

Anis Bedhiafi picture Anis Bedhiafi · Nov 27, 2013 · Viewed 7.2k times · Source

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.

Answer

Dean Winchester picture Dean Winchester · Nov 28, 2013

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>