Search code examples
jsptomcatweb.xmlcontext-param

Comparison failure between a variable string and a context param value using fn:startsWith


With the following piece of code, if s_dlText starts with the string "Shipping costs", the code inside the c:when instruction is executed (the word "Pass1" appears in the resulting page):

<c:choose>
  <c:when test="${fn:startsWith(s_dlText, 'Shipping costs') == true}">
    <br />
    Pass1
    <br />
  </c:when>
</c:choose>

Whereas in the following case and again, if s_dlText starts with the string "Shipping costs", the code inside the c:when instruction is not executed (the word "Pass2" does NOT appear in the resulting page):

<c:choose>
  <c:when test="${fn:startsWith(s_dlText, S_SHIPPING_COSTS) == true}">
    <br />
    Pass2
    <br />
  </c:when>
</c:choose>

S_SHIPPING_COSTS is declared as follows in web.xml:

<context-param>
  <param-name>S_IF_MSG_SHIPPING_COSTS</param-name>
  <param-value><![CDATA[Shipping costs]]></param-value>
</context-param>

Do you see what's not being done the right way? Thanks.

NOTE 1

Note that, if I remove the <![CDATA[]]> markup, the behavior is the same.


Solution

  • Use : <c:when test="${fn:startsWith(s_dlText, initParam.S_SHIPPING_COSTS)}"> and you do not need <![CDATA[]]> markup in your web.xml