简体   繁体   English

JavaScript中的jsp标记

[英]jsp tag inside javascript

i have objects of two classes which returning from servlet on jsp page. 我有两个类的对象,它们从jsp页面上的servlet返回。

public class Port {

private String portName;
private boolean acceptability;

//getters and setters ... }

this is my Components class which have Ports objects 这是我的具有Ports对象的Components类

public class Component {



private int id;

private String name,icon;

private List<Port> inputPorts;

private List<Port> outputPorts;

//getters and setters ...


}

this is my java script code 这是我的Java脚本代码

 <script> makeComponent("Menu", "image.png", "green", [makePort("input", true)], [makePort("output", false)]); </script> 

and i want to put object value inside script tag 我想将对象值放在脚本标签内

i tried this but it is not working 我尝试了这个,但是没有用

 <script>
<c:forEach items="${components}" var="component">                           

    makeComponent("${component.name}", "image.png", "green",
          [<c:forEach items="$components.inputPorts" var="inputPort">
                makePort("$inputPort.portName", ${inputPort.acceptability}),

          </c:forEach>],
          [makePort("OUT", false)]
);
</c:forEach>  </script>

is this logic correct? 这个逻辑正确吗? can i use jstl tags in javascript block? 我可以在javascript块中使用jstl标签吗?

exception was ',' after makePort function 在makePort函数之后,异常为“,”

i added: <c:if test="${!loop.last}">,</c:if> this code and it works 我添加了: <c:if test="${!loop.last}">,</c:if>此代码,它可以正常工作

<c:forEach items="${components}" var="component">                           

makeComponent("${component.name}","images/55x55.png","green",
        [
             <c:forEach items ="${component.inputPorts}" var="port" varStatus="loop">

                makePort("${port.portName}", ${port.acceptability})
                <c:if test="${!loop.last}">,</c:if>

             </c:forEach>
        ],
        [
            <c:forEach items ="${component.outputPorts}" var="port">
            makePort("${port.portName}", ${port.acceptability})
            <c:if test="${!loop.last}">,</c:if>

         </c:forEach>
        ]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM