2017-06-19 87 views
1

我使用intellij和gradle構建war和tomcat來運行服務器。JSTL不評估c:如果有的話

這裏是我的build.gradle

apply plugin: 'idea' 
apply plugin: 'eclipse' 
apply plugin: 'war' 

import org.apache.tools.ant.filters.ReplaceTokens 

compileJava { 
    sourceCompatibility = 1.8 
    targetCompatibility = 1.8 
} 

eclipse.classpath.downloadSources = true 
eclipse.classpath.downloadJavadoc = true 

war.archiveName "paths.war" 
repositories { 
    maven { url 'https://repo.maven.apache.org/maven2/' } 
    flatDir(dirs: 'dep-lib') 
} 

dependencies { 
    providedCompile 'javax.servlet:javax.servlet-api:3.1.+' 
    providedCompile 'javax.servlet.jsp:javax.servlet.jsp-api:2.3.+' 

    // explicit, so that we don't get the jar file in the project 
    compile 'log4j:log4j:1.2.+' 

    compile 'org.apache.commons:commons-lang3:3.+' 
    compile 'commons-validator:commons-validator:1.4.+' 


    compile 'javax.servlet:jstl:1.2' 
    compile 'org.json:json:20140107' 

    testCompile 'junit:junit:5.+' 
    testCompile 'commons-io:commons-io:2.4' 
    testCompile group: 'org.springframework', name: 'spring-core', version: '4.2.6.RELEASE' 
    testCompile group: 'org.springframework', name: 'spring-test', version: '4.2.6.RELEASE' 
} 

task versionWebXml(type: Copy) { 
    println("Copy") 
    from('src/main/webapp/WEB-INF/') { 
     filter(ReplaceTokens, tokens: project.ext.properties) 
     include 'web.xml' 
    } 
    println("${buildDir}") 
    into "${buildDir}" 
} 

war { 
    println("WAR") 
    webInf { 
     setDuplicatesStrategy "EXCLUDE" 
    } 
    webXml = file("${buildDir}/web.xml") 
} 


task devDeploy(type: Copy) { 
    if (file("dev.properties").exists()) { 
     ext.devProps = new Properties() 
     devProps.load(new FileInputStream("dev.properties")) 
     from war.archivePath 
     into devProps['deployDir'] + "/webapps/" 
    } 
} 

war.dependsOn versionWebXml 
war.dependsOn test 
devDeploy.dependsOn war 

我有以下代碼

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<body> 
    <c:set var="solution" value="${path}"/> 
    <% System.out.println(PageContext.REQUEST); %> 

    <c:if test="${true}"> 
     IF TRUE 
    </c:if> 
    <c:choose> 
     <c:when test="${true}"> 
      TRUE 
     </c:when> 
     <c:otherwise> 
      FALSE 
     </c:otherwise> 
    </c:choose> 
</body> 

頁,渲染時,不評估任何的C:如果或c:當

它只顯示FALSE

我不知道爲什麼它不能正確呈現。

任何幫助?

+0

假設要檢查'$ {true}'你應該將一個變量從你的controller/servlet傳遞到JSP頁面。參考這個例子[post](http://www.java2s.com/Tutorial/Java/0380__JSTL/JSTLIfElseStatement.htm) –

+0

通常你想測試一個變量是否等於某個東西 - 是** test **的名字你的變量? –

+0

另外,你的gradle的相關性是什麼? –

回答

-1

,你可以刪除代碼:

<% System.out.println(PageContext.REQUEST); %>

,然後再試一次。

+0

這將如何幫助? –

+0

@John Hamlett IV: 我有一個類似的問題,當我使用jstl <%一些評論%>,我什麼也沒有。當我刪除內容<% ... %>時,它運行正常。我完全不知道原因,但我希望它對你有用。這對你有效嗎? – Jian

+0

@John Hamlett IV,我查看了你的問題agiain,我想我誤解了你的困惑,而你<% ... %>不在之內,對不起,忘了我的回答。 – Jian