我是 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
url 时,它都会显示 404 错误。请帮我。此外,当我更改recvHttpGet
方法 时return "index"
,它也会显示 404 错误。也没有向控制台写入任何内容。
我只想检查哪些方法调用所以想在控制台窗口中写入,但它没有显示任何内容。