加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Spring启动MVC:找不到JSP

发布时间:2020-12-14 16:35:29 所属栏目:Java 来源:网络整理
导读:问题:我无法在我的 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.springfram
问题:我无法在我的 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>

这是我的控制器:

@Controller
public class UtenteController {

    @Autowired
    private UtenteService utenteService;

    @RequestMapping("/lista_utenti")
    public ModelAndView getListaUtentiView(){
        ModelMap model = new ModelMap();
        model.addAttribute("utenti",this.utenteService.getListaUtenti());
        return new ModelAndView("lista_utenti",model);
    }

}

这是我的application.properties:

# 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

我究竟做错了什么?

解决方法

Zio,你确定你把这个依赖包括在你的pom上吗?
<dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
   <scope>provided</scope>
</dependency>

没有这个,我得到了同样的错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读