小弟有一需求,需要在Action(框架是S2SH)中从数据库里查出一个List ,我怎么样将这个List传到JSP页面中的javascript中
以下是一个dtree,不过数据是写死了的,我想从数据库中拿到数据然后在dtree中动态写活(数据库中ID,父ID,名字,等参数都有),我用的是struts2。action 和 javascript该怎么写了?
代码如下:
public String toList() {return "toTest";
}(action 拦截器)
<link rel="StyleSheet" href="dtree.css" type="text/css" />   
<script type="text/javascript" src="dtree.js"></script>  
  </head>
   
  <body>
  <div class="dtree"><p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p><script type="text/javascript">
<!--d = new dTree('d');d.add(0,-1,'My example tree');
d.add(1,0,'Node 1','example01.html');
d.add(2,0,'Node 2','example01.html');
d.add(3,1,'Node 1.1','example01.html');
d.add(4,0,'Node 3','example01.html');
d.add(5,3,'Node 1.1.1','example01.html');
d.add(6,5,'Node 1.1.1.1','example01.html');
d.add(7,0,'Node 4','example01.html');
d.add(8,1,'Node 1.2','example01.html');
d.add(9,0,'My Pictures','example01.html','Pictures I\'ve taken over the years','','','img/imgfolder.gif');
d.add(10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir');
d.add(11,9,'Mom\'s birthday','example01.html');
d.add(12,0,'Recycle Bin','example01.html','','','img/trash.gif');document.write(d);//-->
</script></div>
  </body>

解决方案 »

  1.   

    你可以将值保存在sessin里面 然后放到页面上  在jsp里面通过document.getElementById("")得到数据!!!
      

  2.   

    返回json类型的数据遍历试试吧
      

  3.   

    我前几天写过DEMO,用的是普通的Servlet,Servlet中存入一个变量“nodes”,是一个list,jsp中是这样写的在body中
    <script type="text/javascript">
    <!--
    d = new dTree('d'); d.add(0,-1,'菜单权限树');//固定的


    <c:forEach items="${nodes}" var="node" > d.add(${node.nodeId},${node.pid},"${node.chechBoxName}","${node.chechBoxValue}","${node.name}");</c:forEach>

    document.write(d);
    d.openAll();
    //-->
    </script>