@RequestMapping在春天不起作用

时间:2013-08-24 09:04:36

标签: java spring spring-mvc

我是Spring MVC的新手。我在newController.java中创建了一个控制器springproject。我的代码如下:

@RequestMapping(value = "/Receiver", method = RequestMethod.GET)
public void recvHttpGet(Model model) {
    System.out.println("here get");
    newmethod();
}

@RequestMapping(value = "/Receiver", method = RequestMethod.POST)
public void recvHttpPost(Model model) {
    System.out.println("here post");
    newmethod();
}

@RequestMapping(value = "/", method = RequestMethod.GET)
public String show(Model model) {
    return "index";
}

的web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>ClassPath:/spring/applicationContext.xml, ClassPath:/spring/hibernateContext.xml</param-value>
</context-param>

<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>

</servlet-mapping>

每当我尝试运行它时,都会显示index.jsp页面,但每当我尝试拨打/Receiver时,它都会显示404错误。请帮我。此外,当我更改recvHttpGet方法return "index"时,它也会显示404错误。也没有任何内容写入控制台。

我想检查哪些方法调用想要在控制台窗口中编写,但它没有显示任何内容。

1 个答案:

答案 0 :(得分:0)

您需要返回一个JSP页面,就像return "index";

一样

如果您在视图中有receiver.jsp页面,那么......

@RequestMapping(value = "/Receiver", method = RequestMethod.GET)
public String recvHttpGet(Model model) {

    return "receiver";
}