java.lang.ClassNotFoundException: org.apache.xpath

2019-09-16 03:50发布

问题:

I have some code here.

<c:set var="songId" value="${param.songid}"/>
<c:import var="xml" url="WEB-INF/comment.xml" />
<x:parse var="doc" doc="${xml}" scope="session" />
<c:catch var="ex">
<x:forEach var="cmt" select="$doc//*[songId=$songId]" varStatus="counter">
    <li>
        <div class="avacmtSide">
        </div>
        <div class="ctcmtSide">
            <a href="#" style="padding:10px;"><x:out select="$cmt/uploader"/> </a>
            <div style="padding:10px;"><x:out select="$cmt/comment"/> </div>
        </div>
        <div class="clear"></div>
    </li>
</x:forEach>

When I run it there is a error java.lang.ClassNotFoundException: org.apache.xpath.VariableStack. When I search google for this error. People said there is missing xalan library. But I have added xalan-2.7.0.jar in my project and it doesn't work. Anyone who know it please help me. Thanks.

回答1:

The variable syntax is incorrect:

 [songId=$songId]

It should be this:

 "$doc//*[@songId=${pageScope:songId}]"

Using JSTL Data as XPath Variables

Scoped variables can be used in XPath expressions ($implicitObject:variableName) similar to how they are used in EL (${implicitObject.variableName}). If the implicit object is omitted, scopes will be searched in standard order. Note that the “.” and “[]” notations cannot be used for accessing bean properties.

References

  • XPath: Variable Reference

  • JSTL - using variables in an xpath?

  • JSTL Quick Reference