简体   繁体   中英

Spring boot: How to convert thymeleaf to jsp

I recently followed a authentication and authorization tutorial using spring boot. It's working fine and I want to integrate it to my existing project. The tutorial I followed is written in thymeleaf and my current project is in jsp. I tried searching online but it's giving me errors.

This is my code:

Controller

@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;
}

Thymeleaf

<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

在此处输入图片说明

在此处输入图片说明

This is one of the problems that I am encountering. When I tried to run it, it's giving me this error.

/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

This is my first time using this. Hope you could help me. Thank you so much!!

Use this in you jsp instead of what you have:

" <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> "

Without the quotation marks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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