Spring MVC文件org.springframework.web.servlet.DispatcherServlet noHandlerFound

时间:2013-10-02 20:11:03

标签: spring servlets spring-mvc spring-security

我曾尝试多次,但我仍然遇到这些问题,但无法理解这是从哪里出现的。

  

2013年10月2日下午1:50:37   org.springframework.web.servlet.DispatcherServlet noHandlerFound   警告:找不到带URI的HTTP请求的映射   [/Demo/greeting.html]在DispatcherServlet中,名称为“demoServlet”

我的web.xml

<servlet>
        <servlet-name>demoServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/servlet-config.xml</param-value>
        </init-param>
    </servlet>
     <servlet-mapping>
        <servlet-name>demoServlet</servlet-name>
        <url-pattern>*.html</url-pattern>
     </servlet-mapping>

我的servlet-config.xml

<mvc:annotation-driven />
<context:component-scan base-package="com.demo.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/content/" p:suffix=".jsp"></bean>

我的HelloController

@Controller
public class HelloController {

    @RequestMapping(value ="/greeting")
    public String sayHello(Model model){
        model.addAttribute("greeting","Hello World !");
        return "hello";
    }
}

2 个答案:

答案 0 :(得分:3)

我不知道,但这解决了我的问题!! [想知道原问题的原因]

我改变了

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

它完全没问题。)

答案 1 :(得分:0)

尝试替换:

@RequestMapping(value ="/greeting")

使用:

@RequestMapping(value ="/greeting.html")