今天遇到一个问题:
在action方法中,跳转之前,我将查询到的结果放入reslist对象中,如:request.setAttribute("reslist");
在jsp页面中我像用el表达式处理它。由于存在一个上面的list对象是一个表格的数据源。当选中jsp页面表格中的内容的时候,我试图在JavaScript方法中,重新查找reslist对象,获得用户选择的数据内容。如:
jsp页面:
导入模型对象类。
<%@ page import="com.mytest.Person" %>
js方法:
function myfun(){
    int i = "1";//具个例子,在js方法中我先得到了用户选择表格中的第几行的索引index的值。这里假设值是1,第二行。
    window.opener.document.getElementById("ttid").value='${((Person)reslist.get(i)).getTtid()}';
}
上面myfun()里的第二行,当运行jsp文件时保存,用//注释掉都不行。我像知道,上面再js中写的el不能用吗?不支持还是我的写法有问题?

解决方案 »

  1.   

    写错了吧,js里面也是可以用el表达式的,
      

  2.   

    el表达式这么用就是不对的,没有向你这种写法吧${((Person)reslist.get(i)).getTtid()}
      

  3.   

    "${((Person)reslist.get(i)).getTtid()}"
    这样写肯定有问题. 最好写一个隐藏域, <input type="hidden" name="tableIndex">
    当用户选择哪个表格中的那一行时候
    把index赋给这个隐藏域.再用
    window.opener.document.getElementById("ttid").value = 
    document.getElementsByName("tableIndex").value; 
      

  4.   

    在js中
    var array = new Array();
    <c:forEach var="person" items="${reslist}">
            var obj = new Object();
    obj.attr1 = ${person.attr1}
            obj.attr2 = ${person.attr2}
            .......
            array.push(obj);
    </c:forEach>
    不知道这么写可以不,可以试试