gpt4 book ai didi

java - 为什么 Spring MVC 会出现 404 错误?

转载 作者:行者123 更新时间:2023-12-02 01:17:31 24 4
gpt4 key购买 nike

我有一个简单的 Spring MVC 应用程序。我收到 HTTP 状态 404 报告。帮我解决这个问题。谢谢。

HTTP Status 404 – Not Found

Type Status Report

Message /WEB-INF/users_view.jsp

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.0.M26

我的 Controller :

@Controller
public class UserController {

@RequestMapping(value = "/users", method = RequestMethod.GET)
public String showUsers(ModelMap model) {
return "users_view";
}
}

项目结构:

enter image description here

我的web.xml:

<display-name>User</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Process application servlet -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

applicationContext.xml:

<?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"
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">

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>

<context:component-scan base-package="ru.pravvich" />

</beans>

最佳答案

由于您的 jsp 位于 WEB-INF/view 下,且 InternalResourceViewResolver 前缀指向 /WEB-INF/,您遇到 404 错误。要修复此问题,请将前缀更改为 /WEB-INF/view/

关于java - 为什么 Spring MVC 会出现 404 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45646882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com