1

I am using intellij and gradle to build the war and tomcat to run the server.

Here is my 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

I have the following code

<%@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>

The page, when rendered, does not evaluate any of the c:if or c:when

It only displays FALSE

I have no idea why it is not rendering correctly.

Any help?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
John Hamlett IV
  • 495
  • 11
  • 23
  • suppose rather checking `${true}` you should pass a variable from your controller/servlet to the JSP page. refer this example [post](http://www.java2s.com/Tutorial/Java/0380__JSTL/JSTLIfElseStatement.htm) – Rajith Pemabandu Jun 19 '17 at 00:49
  • usually you want to test if a variable is equal to something - is **test** the name of your variable? – Scary Wombat Jun 19 '17 at 00:55
  • Also, what is the relevance of your gradle? – Scary Wombat Jun 19 '17 at 00:55
  • I am aware what you usually test in c:if however this is a test example that is to show that it doesn't even evaluate it. Unless I am mistaken wouldn't the ${true} cause the c:if to evaluate true? As for the gradle it is showing that I am including the JSTL library. – John Hamlett IV Jun 19 '17 at 00:57

1 Answers1

-1

you could delete the code :

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

and try again.

Jian
  • 54
  • 3
  • How would that help? – John Hamlett IV Jun 19 '17 at 01:27
  • @John Hamlett IV: i had a similar problem when i using jstl <% some comments %> , and i got nothing too. when i delete the content <% ... %> , it ran correctly. i dont konw the exactly reason, but i hope it could useful to you. is that take effect for you? – Jian Jun 19 '17 at 03:14
  • @John Hamlett IV, i viewed your question agiain, i think i misunderstanding your confusion,and you <% ... %> not inside or too, sorry, forget my answer. – Jian Jun 19 '17 at 03:21