Java 未调用Spring MVC控制器
项目结构如下图所示: web.xml如下所示:Java 未调用Spring MVC控制器,java,spring,servlets,model-view-controller,controller,Java,Spring,Servlets,Model View Controller,Controller,项目结构如下图所示: web.xml如下所示: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javae
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/mvc</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/webapp.WEB-INF/mvc-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
名为“home”的jsp只是一些随机html
但是,当我尝试访问url时
我得到以下错误:
我使用了调试器,甚至没有调用控制器中的方法。因此,spring配置存在问题。我在互联网上搜索了很多次,我的想法都没有了。如果有任何帮助,我将不胜感激。将web.xml文件中org.springframework.web.servlet.DispatcherServlet的url模式中的/mvc改为/mvc/*
这将使所有带有/mvc/*模式的uri路由到spring dispatcher,然后再路由到您的servlet尝试使用此url访问hello servlet。我相信这会有帮助的war文件名为“CatalogFacultate”。在Tomcat内的webapps文件夹中,我还有根webapp。所以我使用的URL是正确的。尝试了一下,没有结果。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="main.java.controller"/>
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/webapp.WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
package main.java.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomePageController {
@RequestMapping(value="/home", method= RequestMethod.GET)
public String hello(){
return "homepage";
}
}