JSP中的Spring MVC请求URL
问题内容:
我正在使用Spring
MVC编写Web应用程序。我正在为控制器等使用批注。除涉及应用程序中的实际链接(表单动作,<a>
标签等)外,其他所有东西都工作正常,目前,我有这个(显然是缩写):
//In the controller
@RequestMapping(value="/admin/listPeople", method=RequestMethod.GET)
//In the JSP
<a href="/admin/listPeople">Go to People List</a>
当我直接输入“ http:// localhost:8080 / MyApp / admin /
listPeople”之类的URL时,页面将正确加载。但是,上面的链接不起作用。它将释放应用程序名称“ MyApp”。
有谁知道是否有一种方法可以配置Spring以在其中使用应用程序名称?
让我知道您是否需要查看我的任何Spring配置。我正在将标准调度程序servlet与视图解析器等配合使用。
问题答案:
您需要在链接之前添加上下文路径。
// somewhere on the top of your JSP
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
...
<a href="${contextPath}/admin/listPeople">Go to People List</a>