Java Spring MVC-正在执行的视图无效(违反指定的请求映射)
我已经试着调试它好几个小时了,甚至试着一次又一次地创建同一个项目。我不知道这是IntelliJ IDEA还是其他原因造成的。我试着用谷歌搜索,但找不到任何解决办法。我正在用intelliJ制作一个简单的spring mvc演示应用程序。intelliJ提供了一个默认结构,web目录中有一个视图“index.jsp” web.xmlJava Spring MVC-正在执行的视图无效(违反指定的请求映射),java,spring,spring-mvc,intellij-idea,Java,Spring,Spring Mvc,Intellij Idea,我已经试着调试它好几个小时了,甚至试着一次又一次地创建同一个项目。我不知道这是IntelliJ IDEA还是其他原因造成的。我试着用谷歌搜索,但找不到任何解决办法。我正在用intelliJ制作一个简单的spring mvc演示应用程序。intelliJ提供了一个默认结构,web目录中有一个视图“index.jsp” web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-mvc-demo</display-name>
<!-- Spring MVC Configs -->
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="com.luv2code.springdemo" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
问题是,每当我运行项目并点击localhost:8080/时,就会执行index.jsp,但根据我的配置和映射,应该加载hello.jsp。我可能犯了一些愚蠢的错误,但我已经尽了最大努力,现在真的很沮丧。请帮帮我。谢谢
本地主机:8080
尝试此映射:
@RequestMapping(value = {"", "/", "index.jsp"}, method = RequestMethod.GET)
我猜localhost:8080等于
”
路径,但不是/
,谢谢你的建议,但它似乎不起作用。仍然加载index.jsp!PS:我已经试过localhost:8080和localhost:8080/完全一样。很奇怪。我用的是SpringBoot,对我来说它很有效…:-(这就是我把它贴在这里的原因。我不知道是什么原因造成的。)/
@RequestMapping(value = {"", "/", "index.jsp"}, method = RequestMethod.GET)