简体   繁体   English

Spring MVC为什么没有找到我的观点的路径?

[英]why isn't Spring MVC finding the path to my views?

I'm new to Spring and I'm trying to make a simple web app, however I cannot get started with the basics and cant make even a HelloWorld application. 我是Spring的新手,正在尝试制作一个简单的Web应用程序,但是我无法开始使用基础知识,甚至无法制作HelloWorld应用程序。

Here is what I am Using: 这是我正在使用的:

Spring 5 Spring boot 2.1 Eclipse Photon, I used the add-on Spring Tools Version 3.9.6 to create the proyect Spring 5 Spring boot 2.1 Eclipse Photon,我使用附加的Spring Tools版本3.9.6创建了proyect

Here is what I did: Created via File -> New -> Spring Starter Proyect, selected type package type as WAR, also in the dependencies section I selected Web 这是我所做的事情:通过File-> New-> Spring Starter Proyect创建,选择类型包类型为WAR,也在我选择的Web的依赖项部分中

Added jstl and jasper dependencies to the pom.xml, here is the whole file: 在pom.xml中添加了jstl和jasper依赖项,这是整个文件:

<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.logback.app</groupId>
<artifactId>spring-boot-logback</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>spring-boot-logback</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.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-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    **<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>           
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>            
    </dependency>**
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

My view template is as follows: 我的视图模板如下:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
 <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1" />
<title>Logback</title>
</head>
<body>
<h1>Hello world</h1>
<h2><c:out value="${titulo}"/></h2>
</body>
</html>

This is my controller: 这是我的控制器:

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {

    @GetMapping("/index")
    public String index(Model model) {
        model.addAttribute("titulo", "Pruebas Logback");
        return "index";
    }
}

And I added these to the application.properties file 然后将它们添加到application.properties文件中

spring.mvc.view.prefix: /WEB-INF-/views/
spring.mvc.view.suffix: jsp

With all these configuration it should work, but when I enter the address localhost:8080/index it throws what it looks like a 404 error 通过所有这些配置,它应该可以工作,但是当我输入地址localhost:8080 / index时,它会抛出看起来像404错误的内容

在此处输入图片说明

And the strangest thing is that neither in the web browser console or in the Eclipse console are errors that point out to the right direction. 最奇怪的是,Web浏览器控制台或Eclipse控制台中的错误均未指出正确的方向。

What do you think it can be? 您认为这可能是什么? Thanks ind advance 感谢ind提前

Thanks to Piotr Podraza I realized my mistake 多亏了Piotr Podraza,我才意识到自己的错误

Changed 已变更

spring.mvc.view.prefix: /WEB-INF-/views/
spring.mvc.view.suffix: jsp

to

spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp

The path to my views was incorrect, and I was missing the period of the jsp suffix 我的观点之路不正确,我错过了jsp后缀的句号

Thank you! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM