Jsp used in the EL expression calls the problem matches method of the String class

What to do: matches a string if a decimal point, it is rounded; if not digital, direct display

Look at the correct implementation:  

<c:set var="reg" value="\d+\.?\d+" />
<c:if test="${expPerResult.matches(reg)}">
   数字
   <fmt:parseNumber integerOnly="true" value="${expPerResult}" />
</c:if>
<c:if test="${!expPerResult.matches(reg)}">
  非数字
   ${expPerResult}
</c:if>

Before the error wording:

<c:if test="${expPerResult.matches('\d+\.?\d+')}">  
  数字
  <fmt:parseNumber integerOnly="true" value="${expPerResult}" />
</c:if>
<c:if test="${!expPerResult.matches('\d+\.?\d+')}">
  
非数字
  ${expPerResult}
</c:if>

Background Abnormal content:

  java.lang.IllegalArgumentException: The expression [${expPerResult.matches('\d+\.?\d+')}] is not valid. Within a quoted String only [\], ['] and ["] may be escaped with [\].

Summary: When using the expression el call String methods of matches, the best regular expression passed as a variable, as shown abnormal reasons: to avoid in the expression "\."

Guess you like

Origin www.cnblogs.com/HF-Made/p/11607123.html