在JSP页面上的脚本标记

在JSP页面上的脚本标记

本文介绍了如何使用< c:forEach>在JSP页面上的脚本标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想使用JSTL数据传递数据表



我的代码是这样的:


$ b $ $ $ $ $ $ $ $ $ (document).ready(function(){

$ b $ / * Init DataTables * /
var startString =[;
var mainString =;
var endString =];


var temp = $ {k.size()};
temp--;
if(temp === 0){
mainString = mainString +{key:\ +$ {stdn.key}+\,名称:\+$ {stdn.value.name}+\,rollno:\+$ {stdn。标记:\+$ {stdn.value.marks}+\};
} else {
mainString = mainString +{key:\+$ {stdn.key}+\,名称:\+$ {stdn.value.name}+\,rollno:\\ \\+$ {stdn.value.rollNo}+\,标记:\+$ {stdn.value.marks}+\},;
}
< / c:forEach>
var finalString = startString + mainString + endString;
var final = eval(finalString);


解决方案
 < %@ taglib uri =http://java.sun.com/jsp/jstl/coreprefix =c%> 
< html>
< head>
< title>< c:forEach>您的代码< / title>
< / head>
< body>
< c:forEach var =ibegin =1end =5>
NAME< c:out value =$ {i}/>< p>
< / c:forEach>
< / body>
< / html>

这会产生以下结果:

 名称1 
名称2
名称3
名称4
名称5

$ b

上面是最简单的例子。
下面是项目var

 <表> 
< c:forEach var =studentitems =$ {person.person}varStatus =counter>
< c:when test =$ {counter.count%2 == 0}>
< c:set var =rowStylescope =pagevalue =odd/>
< / c:当>
< c:否则>
< c:set var =rowStylescope =pagevalue =even/>
< / c:否则>
< / c:选择>
< tr class =Ã$ {rowStyle}>
< td> $ {student.name}< / td>
< td> $ {student.age}< / td>
< td> $ {student.height}< / td>
< / tr>
< / c:forEach>
< / table>

这样您就可以使用< c:forEach> < / c:forEach> TAG ..



如果您有任何具体问题,请解释

Hey How to use loop in tag in jsp page?

i want to use JSTL data to pass in data tables

my code is like :

        $(document).ready(function() {


            /* Init DataTables */
            var startString = "[";
            var mainString = "";
            var endString = "]";


            var temp = ${k.size()};
        <c:forEach items="${k}" var="stdn" varStatus="status">
            temp--;
            if (temp === 0) {
                mainString = mainString + "{key:\"" + "${stdn.key}" + "\",name:\"" + "${stdn.value.name}" + "\",rollno:\"" + "${stdn.value.rollNo}" + "\",marks:\"" + "${stdn.value.marks}" + "\"}";
            } else {
                mainString = mainString + "{key:\"" + "${stdn.key}" + "\",name:\"" + "${stdn.value.name}" + "\",rollno:\"" + "${stdn.value.rollNo}" + "\",marks:\"" + "${stdn.value.marks}" + "\"},";
            }
        </c:forEach>
                var finalString = startString + mainString + endString;
                var final = eval(finalString);
解决方案
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:forEach>YOUR CODE </title>
</head>
<body>
<c:forEach var="i" begin="1" end="5">
   NAME <c:out value="${i}"/><p>
</c:forEach>
</body>
</html>

This would produce following result:

NAME 1
NAME 2
NAME 3
NAME 4
NAME 5

Above is simplest example..following is with items var

<table>
      <c:forEach var="student" items="${person.person}" varStatus="counter">
        <c:choose>
          <c:when test="${counter.count % 2 == 0}">
            <c:set var="rowStyle" scope="page" value="odd"/>
          </c:when>
          <c:otherwise>
            <c:set var="rowStyle" scope="page" value="even"/>
          </c:otherwise>
        </c:choose>
        <tr class="ÃÂ${rowStyle}">
          <td>${student.name}</td>
          <td>${student.age}</td>
          <td>${student.height}</td>
        </tr>
      </c:forEach>
    </table>

this way you can use the <c:forEach> </c:forEach> TAG..

If you have any specific problem then please explain

这篇关于如何使用&lt; c:forEach&gt;在JSP页面上的脚本标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:49