我按照这篇文章使用 JSTL 变量呈现 javascript 变量:
var size= "<c:out value='${fn:length(orders)}'/>";
但是,不太幸运,我遇到了这样的异常:
Element type "size" must be followed by either attribute specifications, ">" or "/>".
所以我用
var size= <c:out value='${fn:length(orders)}'/>;
相反,但没有运气。添加双引号后:
var size= "<c:out value='${fn:length(orders)}'/>";
仍然无法正常工作..那么如何逃脱并使其工作?
更新 1
jspx 看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jsp:root
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:page="urn:jsptagdir:/WEB-INF/tags/form"
xmlns:spring="http://www.springframework.org/tags"
xmlns:form="http://www.springframework.org/tags/form"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
version="2.1">
<div>
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<jsp:output omit-xml-declaration="yes"/>
<page:show>
<form:form.....
<!--body of the form -->
</form:form>
</page:show>
<script type="text/javascript">
//jquery and so...
....
var size= "<c:out value='${fn:length(orders)}'/>";
....
</script>
</div>
</jsp:root>