当在tomcat中部署war时,jstl函数不会在spring引导Web应用程序中呈现

时间:2017-10-25 05:53:31

标签: jsp spring-boot jstl jsp-tags jstl-functions

当在tomcat jstl中部署的spring boot web应用程序没有渲染时。在这个问题上帮助我         在tomcat中部署战争时应该做些什么改变 添加依赖:

<parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.2.RELEASE</version>
        </parent>

        <properties>

            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
            <start-class>com.**.BootConfig.Application.java</start-class>
        </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>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
            </dependency>

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

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

            <dependency>
                <groupId>taglibs</groupId>
                <artifactId>standard</artifactId>
                <version>1.1.2</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-taglibs</artifactId>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.webjars</groupId>
                <artifactId>jquery</artifactId>
                <version>2.2.4</version>
            </dependency>

            <dependency>
                <groupId>org.webjars</groupId>
                <artifactId>bootstrap</artifactId>
                <version>3.3.7</version>
            </dependency>

            <dependency>
                <groupId>org.eclipse.jdt.core.compiler</groupId>
                <artifactId>ecj</artifactId>
                <version>4.6.1</version>
                <scope>provided</scope>
            </dependency>

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

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
            </dependency>

            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
            </dependency>

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

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

我尝试使用的jsp页面功能

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%@ taglib prefix="coe" tagdir="/WEB-INF/tags"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

这里的页面中没有渲染这些函数。只是按原样打印。

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%@ taglib prefix="coe" tagdir="/WEB-INF/tags"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

我们是否需要添加任何特定于使用所有这些功能的内容。还有什么需要发布的。让我知道。

添加jsp页面。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="coe" tagdir="/WEB-INF/tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">


<!-- ----CSS Files ----- -->
<link type="text/css" rel="stylesheet"
    href="<c:url value="/css/bootstrap.min.css"/>" />
<link type="text/css" rel="stylesheet"
    href="<c:url value="/font-awesome/css/font-awesome.min.css"/>" />
<link type="text/css" rel="stylesheet"
    href="<c:url value="/css/owl.carousel.css"/>" />
<link type="text/css" rel="stylesheet"
    href="<c:url value="/css/style.css"/>" />
<link type="text/css" rel="stylesheet"
    href="<c:url value="/css/style_home.css"/>" />
<link type="text/css" rel="stylesheet"
    href="<c:url value="/css/responsive.css"/>" />
<link type="text/css" rel="stylesheet"
    href="<c:url value="/css/dataTables.bootstrap.css"/>" />

<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144"
    href="/resource/static/images/fav-144.html">
<link rel="apple-touch-icon-precomposed" sizes="114x114"
    href="/resource/static/images/fav-114.html">
<link rel="apple-touch-icon-precomposed" sizes="72x72"
    href="/resource/static/images/fav-72.html">
<link rel="apple-touch-icon-precomposed"
    href="/resource/static/images/fav-57.html">
<link rel="shortcut icon" href="images/fav.html">

<!-- Google Web Fonts -->
<link
    href="http://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,400italic,700italic,400,300,700"
    rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Oswald:400,700,300"
    rel="stylesheet" type="text/css">
<link
    href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,700,300,600,800,400"
    rel="stylesheet" type="text/css">


<!-- ----JAVA SCRIPT----- -->
<script type="text/javascript"
    src="<c:url value="/js/jquery-1.11.1.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/js/jquery-migrate-1.2.1.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/js/bootstrap.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/js/bootstrap-hover-dropdown.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/js/jquery.magnific-popup.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/js/owl.carousel.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/custom.js"/>"></script>


</head>
<body class="back">
    <!-- Header Section Starts -->
    <header id="header-area"> <!-- Header Top Starts -->
    <div class="header-top-home">
        <div class="container">
            <div class="row">
                <!-- Header Links Starts -->
                <div class="col-sm-8 col-xs-12">
                    <div class="header-links-home">
                        <ul class="nav navbar-nav pull-left">

                        </ul>
                    </div>
                </div>
                <!-- Header Links Ends -->
                <!-- Right Navigation -->
                <div class="col-sm-4 col-xs-12">
                    <div class="pull-right header-links-home">
                        <ul class="nav navbar-nav pull-right">

                        </ul>
                    </div>
                </div>
                <!-- Right Navigation -->
            </div>
        </div>
    </div>
    <!-- Header Top Ends --> <!-- Main Header Starts -->
    <div class="main-header back1">
        <div class="container">
            <div class="row">
                <div class="col-sm-2"></div>


            </div>
        </div>
    </div>
    </header>
    <nav id="main-menu" class="navbar" role="navigation">
    <div class="container">
        <!-- Nav Header Starts -->
        <div class="navbar-header">
            <button type="button" class="btn btn-navbar navbar-toggle"
                data-toggle="collapse" data-target=".navbar-cat-collapse">
                <span class="sr-only">Toggle Navigation</span> <i class="fa fa-bars"></i>
            </button>
        </div>
        <coe:menu userrole="${role}" offeringList="${offeringList}" />
    </div>
    </nav>
    <div id="main-container-home" class="container">
        <div class="row">
            <div class="col-sm-3"></div>
            <div class="col-md-6">

            </div>
            <div class="col-sm-3"></div>
        </div>
        <div class="row">
            <c:forEach items="${OfferingDetails}" var="val" varStatus="loop">
                <div class="col-md-2 col-sm-4 col-xs-6">
                    <div class="dummy"></div>
                    <a href="offeringList.html?val=${val.offName}"
                        class="thumbnail ${val.offColor}"><i class="${val.offIcon}"></i><br>${val.offName}</a>
                </div>
            </c:forEach>
        </div>
        <h3 style="font-size: 18px" class="product-head">My Subscribed
            Solutions:-</h3>


    <!-- Footer Section Starts -->
    <footer id="footer-area"> <!-- Footer Links Starts --> <!-- Footer Links Ends -->

     </footer>

</body>
</html>

控制器部分

@RequestMapping(value="/homePage", method = RequestMethod.GET)
    public String homePage(Map<String, Object> model){

        Authentication auth = SecurityContextHolder.getContext()
                .getAuthentication();
        String name = auth.getName();

        System.out.println("name    "+    name + auth.getAuthorities());
        List<String> offeringList=loginService.getOfferingList();
        model.put("offeringList", offeringList);
        System.out.println(offeringList.size());

        List<OfferingDetails> OfferingDetails=loginService.getOfferingDetailsTable();
        model.put("OfferingDetails", OfferingDetails);

        List<String> hashTag=loginService.getHashTags();
        model.put("hashTag",hashTag);

        Set<SolutionDetails> downloadDetails=loginService.getUserDownloadDetails();
        model.put("downloadDetails", downloadDetails);

        String role=getRole();
        model.put("role",role);

        return "homePage";
    }

jars available in class path

2 个答案:

答案 0 :(得分:0)

taglibs

中添加标准pom.xml jar
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

另外,不要忘记首先在jsp中包含标准taglib。

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

答案 1 :(得分:0)

如果您能告诉我们您正在使用的Tomcat版本,那将会有所帮助。此外,当您对项目执行mvn spring-boot:run时,它是否会为您提供预期结果?如果是,那么它指向TC安装上的配置问题,或者TC预打包的jar正在使用您的app创建的类路径问题或不兼容性。