Java Can';SpringMVC中的t加载页面
我想在我的spring MVC中添加一个页面。我可以调用索引文件,但不能单击Java Can';SpringMVC中的t加载页面,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,我想在我的spring MVC中添加一个页面。我可以调用索引文件,但不能单击index.jsp中的链接来显示页面product.jsp。其错误消息为“请求的资源不可用” 以下是我的控制器代码: @RequestMapping({"/", "/index"}) public String index(ModelMap model, HttpSession session, Principal principal) throws Exception { return "index"; }
index.jsp
中的链接来显示页面product.jsp
。其错误消息为“请求的资源不可用”
以下是我的控制器代码:
@RequestMapping({"/", "/index"})
public String index(ModelMap model, HttpSession session, Principal principal) throws Exception {
return "index";
}
@RequestMapping({"/product"})
public String product(ModelMap model, HttpSession session, Principal principal) throws Exception {
return "product";
}
这个index.jsp
<div class="row">
<div class="col-sm-4 menu-img-pad">
<ul class="multi-column-dropdown">
<li><a href="../product.jsp">Joggers</a></li>
<li><a href="../product.jsp">Foot Ball</a></li>
<li><a href="../product.jsp">Cricket</a></li>
</ul>
</div>
</div>
您需要定义一个ViewResolver,以便让spring知道如何查找视图
看一看。在你的情况下,一个新的方法会起作用
然后,为了调用您的处理程序,您的链接应该指向
/product
,因为您在@RequestMapping
方法中定义了路径将下面的配置添加到dispatcher-servlet.xml
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
在上面的配置中,“视图”是容器将在其中查找product.jsp文件的文件夹名。尝试以下操作:
为product.jsp提供绝对路径,或者将文件(index.jsp和product.jsp)保持在同一文件夹中。@Aamir>文件夹>index.jsp和product位于与文件夹相同的位置。@Cáphđen它不起作用。