这个问题不简单呀?javascript在客户端,你定义的类在服务器端,怎么调用呢?

解决方案 »

  1.   

    这个是不太容易阿。我在程序当中,有这种情况,我想从数据库中选出相关的数据放入到数组中,然后在javascript中使用这个数组,我是这样作的:
    1。在jsp中选出需要的数据,并放入一个String数组中;
    2。在javascript中,将String数组存放在一个javascript中的数组中;
    3。这样就可以在javascript调用那个数组了。
    下面是源码,希望对你有帮助,如果有不清楚,可给我邮件:[email protected]<jsp:useBean id = "mocata" class = "com.keysoft.smsbean.QueryMobileCata" scope = "page" /><% String thisurl = "";
    int rcdNum = 0; ResultSet cata = null; cata = mocata.getAllMobileCata();
    rcdNum = mocata.getRecordCount();
    %><script language="Javascript">
    menu1 = new Array();
    var tmp,tmp1;
    var temp; temp = 1;

    </script>
    <%  
    int temp;
    temp = 0;
    while(cata.next())
    {
    temp = temp + 1;

    %>
    <script language="Javascript"> menu1[<%=temp%>] = new Array(5);
    tmp = "<%=cata.getString("id")%>";
    if(tmp != "null" && tmp != "")
    {
    menu1[<%=temp%>][1] = tmp;
    tmp2 = "<%=cata.getString("parentid")%>"; if(tmp2 != "null" && tmp2 != "")
    {
    menu1[<%=temp%>][2] = tmp2;
    }
    else
    {
    menu1[<%=temp%>][2] = "0";
    } tmp2 = "<%=cata.getString("name")%>";
    if(tmp2 != "null" && tmp2 != "")
    {
    menu1[<%=temp%>][3] = tmp2;
    }
    else
    {
    menu1[<%=temp%>][3] = "";
    }

    tmp2 = "<%=cata.getString("filename")%>";
    if(tmp2 != "null" && tmp != "")
    {
    tmp2 = tmp2 + "?cid=" + menu1[<%=temp%>][1];
    menu1[<%=temp%>][4] = tmp2;
    }
    else
    {
    menu1[<%=temp%>][4] = "";
    }
    menu1[<%=temp%>][5] = "smsmain"; } </script><%
       
       }
    %>