[英]The requested resource is not available error in Spring Web MVC
根據錯誤消息,您似乎沒有在Tomcat中定義上下文。
在META-INF文件夾中包含一個名為context.xml的文件,內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/HelloWeb"/>
從tomcat文檔:
各個上下文元素可以明確定義:
在應用程序文件內/META-INF/context.xml中的單個文件中。 (可選)(基於主機的copyXML屬性),可以將其復制到$ CATALINA_BASE / conf / [引擎名稱] / [主機名稱] /,並重命名為應用程序的基本文件名加上“ .xml”擴展名。
另外,返回ModelView對象而不是String來重定向到您的home.jsp頁面。
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView printHello(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView("hello");
return model;
}
像這樣替換您的bean標簽。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.