簡體   English   中英

Spring Boot:如何將百里香葉轉換為JSP

[英]Spring boot: How to convert thymeleaf to jsp

我最近遵循了使用Spring Boot的身份驗證和授權教程。 它工作正常,我想將其集成到我現有的項目中。 我遵循的教程是用thymeleaf編寫的,而我當前的項目是使用jsp。 我嘗試在線搜索,但出現錯誤。

這是我的代碼:

控制者

@RequestMapping(value = { "/","/welcome" }, method = RequestMethod.GET)
public ModelAndView test() {
    ModelAndView model = new ModelAndView("welcomePage");
    model.addObject("title","Welcome");
    model.addObject("message","This is welcome page");
    return model;
}

胸腺

<a th:if="${#request.userPrincipal != null}" th:href="@{/logout}">Logout</a>

JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

    <div>
        <a href="/">Home</a> | &nbsp; 
        <a href="/userInfo">User Info </a> | &nbsp; 
        <a href="/admin">Admin</a> | &nbsp; 

        <c:if test="${pageContext.request.userPrincipal != null}">
            <h2>Logout</h2> 
            <br>
        </c:if>


        ${pageContext.request.userPrincipal}



    </div>

</body>
</html>

pom.xml

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</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>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <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>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

application.properties

在此處輸入圖片說明

在此處輸入圖片說明

這是我遇到的問題之一。 當我嘗試運行它時,它給了我這個錯誤。

/WEB-INF/jsp/_menu.jsp (line: [18], column: [2]) According to TLD or attribute directive in tag file, attribute [test] does not accept any expressions

這是我第一次使用。 希望你能幫助我。 非常感謝!!

在您的jsp中使用它,而不是您擁有的東西:

“ <%@ taglib前綴=” c“ uri =” http://java.sun.com/jsp/jstl/core“%>”

不帶引號

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM