spring-mvc - 错误 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>
解决方案
应用程序无法找到请求的资源基本上告诉您没有任何与请求的 URL 匹配的映射。
尝试在请求映射 url 中添加斜杠,如下所示。
@RequestMapping("/")
推荐阅读
- r - 更改日期格式并在 R 中的图表中保持时间顺序
- html - 如何将表格中的标签对齐?
- c - C 关系运算符 if-else
- python - 测试类似字符串在一个脚本中有效,但在另一个脚本中无效
- java - java.lang.RuntimeException:org.hibernate.MappingException:无法解析命名类型:org.jadira.usertype.dateandtime.joda.PersistentDateTime
- amazon-web-services - 从 lambda 启用 S3 服务器日志
- python - Python:每个操作数的宽度最多为四位。否则,返回的错误字符串将是:错误:数字不能超过四位
- java - 收到错误:java.sql.SQLSyntaxErrorException:ORA-00904:“VOID”:标识符无效
- python - 使用 \n 在 Qualtrics 中加载有效负载
- azure - 使用 ARM 模板和 Key Vault 创建 Azure SQL 的最佳做法是什么