Reputation: 377
I want to have references on my welcomePage.jsp page to other jsp pages - loginPage.jsp and registerPage.jsp. I tried to use simple like this:
<head>
<title>${title}</title>
</head>
<body>
<jsp:include page="header.jsp"/>
<jsp:include page="_menu.jsp" />
<h1>Welcome to the page!</h1>
<a href="registerPage.jsp">Register</a>
<p>or</p>
<a href="loginPage.jsp">Log In</a>
<p>if you already have an account</p>
<jsp:include page="footer.jsp"/>
</body>
</html>
But I keep getting HTTP Status 404 The requested resource is not available.
I also tried but as a result the contents of the pages I was referencing too just apperead on this welcomePage. Although I need them to be accessible through links only. All the mentioned files are located in WEB-INF/pages. This is my first project with Spring MVC so any help is welcomed.
Upvotes: 1
Views: 2745
Reputation: 2970
I suggest you to go to a controller first, than call a ModelAndView in this controller. This also keeps the relations clear between the JSP files.
To apply this your controller class should be like this:
@Controller
public class LoginPageController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView printLoginPage() {
ModelAndView modelAndView = new ModelAndView("loginPage");
return modelAndView;
}
}
You can also pass parameters from a JSP page to another by going through a controller method.
Upvotes: 0
Reputation: 3055
Suppose, in your configuration, you have set the location of views e.g. /WEB-INF/view/
where you put all of your .jsp files - loginpage.jsp, registerPage.jsp
etc. Now, you can simply access the location of view i.e. /WEB-INF/view/
via pageContext.servletContext.contextPath
.
//For example
href="${pageContext.servletContext.contextPath}/loginpage"
Upvotes: 2