Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring boot MVC:can';找不到JSP_Java_Spring_Jsp_Spring Mvc_Spring Boot - Fatal编程技术网

Java Spring boot MVC:can';找不到JSP

Java Spring boot MVC:can';找不到JSP,java,spring,jsp,spring-mvc,spring-boot,Java,Spring,Jsp,Spring Mvc,Spring Boot,问题:我无法在Spring Boot WEB MVC应用程序的WEB-INF/jsp下访问我的视图 我所做的: 这是我的JSP: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib

问题:我无法在Spring Boot WEB MVC应用程序的
WEB-INF/jsp
下访问我的视图

我所做的:

这是我的JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <ul>
        <%--@elvariable id="users" type="java.util.List"--%>
        <c:forEach items="${utenti}" var="utente">
            <li>
                <c:out value="${utente.getUsername()}"/>
            </li>
        </c:forEach>
    </ul>
</body>
</html>
这是我的应用程序。属性:

# MVC
spring.view.prefix=/WEB-INF/jsp/
spring.view.suffix=.jsp

#Postgres config
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/DB_Test
spring.datasource.username=postgres
spring.datasource.password=postgres
至少,我的主要应用程序是:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SpringWebApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(SpringWebApplication.class, args);
    }

    @Override
    protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
        return application.sources(SpringWebApplication.class);
    }
}
如果我转到
http://localhost:8080/lista_utenti
是:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jan 15 15:59:57 CET 2015
There was an unexpected error (type=Not Found, status=404).
No message available

我做错了什么?

齐奥,你确定你的pom中包含了这个依赖项吗

<dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
   <scope>provided</scope>
</dependency>

org.apache.tomcat.embed
汤姆卡特·贾斯珀
假如
没有这个,我也会犯同样的错误


<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>required</scope>
</dependency>
org.apache.tomcat.embed 汤姆卡特·贾斯珀 必修的

将此添加到我在Intellj中的项目中,它可以工作。

我正在将此添加到我的maven Dependences中,现在它可以工作了

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-tomcat</artifactId>
 <scope>provided</scope>
</dependency>

org.springframework.boot
弹簧启动机tomcat
假如

在pom.xml文件中添加Tomcat嵌入Jasper依赖项

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <version>9.0.30</version>
</dependency>

org.apache.tomcat.embed
汤姆卡特·贾斯珀
9.0.30

如果您已从使用标准thymeleaf项目转移到Bootstrap(如我所做的),请确保删除此依赖项

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

org.springframework.boot
弹簧启动装置

看起来服务器无法找到控制器(不是您提到的JSP文件)。你在启动服务器时有没有出现异常?没有,它实际上启动得很好。。它还显示在控制台上:“Mapped”{[/lista_utenti],methods=[]"…您使用的是嵌入式容器,还是将war文件部署到单独的servlet容器?鉴于您使用的是SpringBootServletializer,我猜是后者,但确定这一点很有用。此外,您是否检查过JSP是否打包在jar或war文件中的预期位置?我使用的是嵌入式容器provi我用最新版本的STS(与Spring初始值设定项相同)上的“向导”从头创建了我的web应用程序。在我的POM上,我只为我的postgres驱动程序jstl和MyBatis添加了几个依赖项。我正在将所有内容打包到war中,并且它位于我预期的位置。很抱歉,但我面临一个类似的问题:您的应用程序是war还是JAR打包的?您将*.jsp文件分别放在WEB-INF目录的什么位置?为什么需要这样做?我认为返回ModelAndView html、jsp或任何其他模板引擎这样简单的东西都可以开箱即用?它可以工作,但仍然对这种依赖性感到困惑。它在使用.jsp时可以工作。如果我想使用.html,但仍然希望Spring为我找到这些视图,该怎么办?如果您正在运行embedded,它是必需的-Jasper是jsp编译器呃,通过intellij运行的嵌入式系统我需要删除提供的作用域(have required),否则会出现相同的错误:\
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>