[英]spring mvc 3.0 HTTP Status 404
我知道這類問題早在這里已經問過了,我經歷了很多問題,但找不到我想要的解決方案。
我一直在為我的測試spring mvc 3.0應用程序獲取“ HTTP狀態404”。 每當我通過瀏覽器點擊“ http://127.0.0.1:8080/com.test.andro/androTest1.jsp
”時。 這是簡單的應用程序。 它應該從文件中讀取文本的第一行,並應返回內容作為響應。 以下是配置文件,有人可以找出問題所在嗎?
------------------------------- web.xml ---------------- ---------------
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
</web-app>
--------------------------------- mvc-dispatcher-servlet.xml ---------- ----------------------------
<beans xmlns="http://www.springframework.org/schema/beans"
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.test.andro" />
</beans>
-----------------------------------------控制器-------- -------------------------------
package com.test.controller;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class AndroController {
@RequestMapping(value="/androTest1.jsp", method=RequestMethod.GET)
@ResponseBody
public String readFromTestFile() {
File file = new File("\resources\test1.txt");
try {
BufferedReader bfr = new BufferedReader(new FileReader(file));
return bfr.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
我使用的是實際的tomcat服務器,而不是Eclipse工作區中的一個。 因此,如果我點擊“ http://127.0.0.1:8080/
”,我會得到tomcat服務器頁面(猜測我的服務器工作正常),但是如果我點擊上面顯示的與項目相關的URL,則會出錯。
如果有人可以告訴我我在這里做錯了,那將非常有幫助。
謝謝
問候,
哈沙德
您的控制器當前尚未注冊為處理程序。 您需要通過聲明以下內容來配置應用程序的MVC端
<mvc:annotation-driven/>
在您的servlet上下文配置中。 添加一個名為mvc-dispatcher-servlet.xml
作為Spring bean配置,並將該行添加到其中。 也不要忘記名稱空間聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.