我已经检查了关于这个警告的其他问题,没有人工作。
IDE:Spring工具套件3.9。4 Java:Oracle Java 8
当我尝试打开网页时,会显示一个错误页面:
正在尝试本地主机:8080
以及控制台的输出:
2018-05-19 19:05:33.080信息30506---[nio-8080-exec-1]o.s.web.servlet。DispatcherServlet:FrameworkServlet“DispatcherServlet”:初始化已开始
2018-05-19:05:33.097 INFO 30506---[nio-8080-exec-1]o.s.web.servlet。DispatcherServlet:FrameworkServlet“DispatcherServlet”:初始化在17毫秒内完成。PageNotFound:在名为“DispatcherServlet”的DispatcherServlet中找不到URI为[/]的HTTP请求的映射
文件夹层次结构:文件夹层次结构
application.properties
spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp
spring.mvc.static-path-pattern: /resources/**
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/Airbnb
spring.datasource.username=root
spring.datasource.password=admin
波姆。xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tecnologias</groupId>
<artifactId>airbnb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Airbnb</name>
<description>Trabajo</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Tomcat for JSP rendering -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
你好jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring Boot</title>
</head>
<body>
<h1>Spring Boot - Prueba de MVC</h1>
<hr>
<h2>Tu nombre es ${name}</h2>
</body>
</html>
指数jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!-- Static content -->
<link rel="stylesheet" href="/resources/css/style.css">
<script type="text/javascript" src="/resources/js/app.js"></script>
<title>Spring Boot</title>
</head>
<body>
<h1>Spring Boot - Prueba de MVC/h1>
<hr>
<div class="form">
<form action="hello" method="post" onsubmit="return validate()">
<table>
<tr>
<td>EIntroduce tu nombre</td>
<td><input id="name" name="name"></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
AirbnbApplication.java
package com.tecnologias.airbnb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@SpringBootApplication
@EnableWebMvc
public class AirbnbApplication implements WebMvcConfigurer{
public static void main(String[] args) {
SpringApplication.run(AirbnbApplication.class, args);
}
}
普鲁巴控制器。JAVA
package com.tecnologias.aribnbController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class PruebaController {
@RequestMapping(value="/", method = RequestMethod.GET)
public String index() {
return "index";
}
@PostMapping("/hello")
public String sayHello(@RequestParam("name") String name, Model model) {
model.addAttribute("name", name);
return "/hello";
}
}
谢谢你的帮助。
编辑
控制台新输出
javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1305) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.31.jar:8.5.31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468) [tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.31.jar:8.5.31]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_171]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.31.jar:8.5.31]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]
解决了,我将@请求映射更改为@Get映射,我再也没有那个错误了。
@GetMapping("/")
public String index() {
return "start";
}
我也得到了所有的. java文件在一个单一的包,就像@Neng Liu告诉我的。
我看到了类似的问题,并尝试将网址从/*映射到/,但它不起作用。我也尝试过直接从浏览器点击网址,但也不起作用。我对Spring不熟悉,有人能帮我吗? 还有我的dispatcherservlet servlet。xml是 最后是我的控制器 我的索引。jsp作为欢迎文件 当我运行时,我可以提交并点击add方法的URL,但我收到警告:在名为“DispatcherServlet”的DispatcherSer
我写了一个spring boot项目。它有三个文件。 appconfig.java HelloController.java 当我尝试运行它时,它出现了错误“没有为名为'DispatcherServlet中URI[/springc1_01/]的HTTP请求找到映射”。这是因为服务器没有找到控制器还是其他原因?THX.
当我把它放在我的url上时,浏览器会显示这样一条消息:“请求的资源(/ChickenTest/index.jsp)不可用。”eclipse控制台会显示这样一条消息:“在名为“DispatcherServlet”的DispatcherServlet中,找不到URI为[/ChickenTest/index]的HTTP请求的映射。” 控制器: mvc配置。xml: web.xml:
我对应用程序进行了配置,并将“DispatcherServlet”编码为viewResolver,如下所示: 处理请求的控制器类如下所示: 视图文件:\WEB-INF\view\welcome.jsp 应用程序结构:欢迎使用应用程序结构 我想配置文件中缺少一些东西,但是我看不见。请问哪里出了问题,什么意思:“没有找到与URI[/WEB-INF/view/welcome.jsp]的HTTP请求映射”
问题内容: 以前我的代码可以正常工作,但是现在我遇到此错误。 我的代码是 Java4sController.java web.xml java4s-servlet.xml My directory structure is 问题答案: 您的代码有两个错字。 2.映射是不正确 因此解决方案是保持一种格式或更改映射。 在web.xml 并使用任何格式,例如 .html,.action,*.do`。 添
我想配置文件中缺少一些东西,但我看不到。 当我放入浏览器-->localhost:8080/procura/notifications-->我在控制台中得到的是-->org.springframework.web.servlet.DispatcherServlet noHandlerFound警告:在名为“DispatcherServlet”的DispatcherServlet中没有找到URI[/