簡體   English   中英

Spring Web MVC中請求的資源不可用錯誤

[英]The requested resource is not available error in Spring Web MVC

親愛的利他主義者,

我正在嘗試運行Spring Web MVC HelloWeb項目,但它始終顯示“請求的資源不可用”錯誤。 關於這個問題,您能幫我嗎?

項目結構:

在此處輸入圖片說明

web.xml文件:

在此處輸入圖片說明

HelloWeb-servlet.xml文件:

在此處輸入圖片說明

HelloController.java文件:

在此處輸入圖片說明

根據錯誤消息,您似乎沒有在Tomcat中定義上下文。

在META-INF文件夾中包含一個名為context.xml的文件,內容如下:

<?xml version="1.0" encoding="UTF-8"?>

<Context path="/HelloWeb"/>

從tomcat文檔:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM