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:
我想在welcomePage.jsp页面上引用其他jsp页面 - loginPage.jsp和registerPage.jsp。我尝试使用这样的简单:
<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.
但我一直收到HTTP状态404请求的资源不可用。
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.
我也尝试了但是因此我引用的页面的内容也只是在这个welcomePage上显示。虽然我需要它们只能通过链接访问。所有提到的文件都位于WEB-INF / pages中。这是我的第一个使用Spring MVC的项目,所以欢迎任何帮助。
2 个解决方案
#1
2
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
.
假设,在您的配置中,您已设置了视图的位置,例如/ WEB-INF / view /你把你所有的.jsp文件放在哪里 - loginpage.jsp,registerPage.jsp等等。现在,你可以通过pageContext.servletContext.contextPath简单地访问视图的位置,即/ WEB-INF / view / 。
//For example
href="${pageContext.servletContext.contextPath}/loginpage"
#2
0
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.
我建议你首先去控制器,而不是在这个控制器中调用ModelAndView。这也保持了JSP文件之间的关系清晰。
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.
您还可以通过控制器方法将参数从JSP页面传递到另一个页面。
#1
2
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
.
假设,在您的配置中,您已设置了视图的位置,例如/ WEB-INF / view /你把你所有的.jsp文件放在哪里 - loginpage.jsp,registerPage.jsp等等。现在,你可以通过pageContext.servletContext.contextPath简单地访问视图的位置,即/ WEB-INF / view / 。
//For example
href="${pageContext.servletContext.contextPath}/loginpage"
#2
0
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.
我建议你首先去控制器,而不是在这个控制器中调用ModelAndView。这也保持了JSP文件之间的关系清晰。
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.
您还可以通过控制器方法将参数从JSP页面传递到另一个页面。