首页 > 解决方案 > 错误 404 tomcat 服务器:请求的资源不可用

问题描述

我在 IntelliJ Idea IDE 中使用 9.0 版的 tomcat 服务器。当我运行应用程序时,服务器无法显示jsp页面,我不知道是什么问题。

我正在尝试创建简单的 spring MVC 项目。我的war文件构建成功,它在tomcat上启动没有错误。

但是,当我调用某些服务时,例如http://localhost:8086/appWeb/,它会给出错误:

类型 状态报告消息描述 请求的资源不可用。

调度程序-servlet

<?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:beans="http://www.springframework.org/schema/c"
   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">


<context:component-scan base-package="com.test.pluto"/>
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>
<beans:property name="prefix" value="/WEB-INF/jsp"/>
<beans:property name="suffix" value=".jsp"/>
</beans>

家庭控制器

@Controller
@RequestMapping("")
public class HomeController {
    @RequestMapping(method = RequestMethod.GET)
    public String hello(ModelMap model){ 
        return "hello";
    }
}

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/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
     version="4.0">
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.form</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"
   xsi:schemaLocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>

标签: spring-mvcintellij-ideatomcat9

解决方案


应用程序无法找到请求的资源基本上告诉您没有任何与请求的 URL 匹配的映射。

尝试在请求映射 url 中添加斜杠,如下所示。

@RequestMapping("/")

推荐阅读