在javascript函数中使用jsp [英] using jsp in javascript function

查看:86
本文介绍了在javascript函数中使用jsp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了此内容,但找不到任何内容. 如果英语不正确,请更正我的问题.

I've searched for this but can't find anything. Please correct my question if it's incorrect english.

这是我的代码: 该代码在我的.jsp文件中!

This is my code: The code is within my .jsp file!

    function drawChart() {
    var data = google.visualization.arrayToDataTable([
        ['Beoordeling', 'Stage Opleider', 'Student'],

        ['1', '1', '4'],

        <% ArrayList < Stelling > alleStellingenLijst2 = new ArrayList < Stelling > ();
        alleStellingenLijst2 = (ArrayList < Stelling > ) request.getAttribute("stellingen");
        for (Stelling s: alleStellingenLijst2) {
            out.println("['1', '" + s.getDeStelling() + "' , '" + s.getDeWaarde() + "'],");
        } %> ]);
    var options = {
        title: 'Laatste competenties',
        hAxis: {
            title: 'Score',
            titleTextStyle: {
                color: 'green'
            }
        },
        vAxis: {
            title: 'Beoordeling nummer',
            titleTextStyle: {
                color: 'green'
            }
        },
        // Allow multiple simultaneous selections.
        selectionMode: 'multiple',
        colors: ['#BEF781', 'green']
    };
    var chart = new      google.visualization.BarChart(document.getElementById('chart_div'));
    chart.draw(data, options);
}

由于某种原因,它不会在<%%>(来自jsp)之间执行代码.

For some reason, it wont execute the code between the <% %> (from the jsp).

此在线页面: http://project-omega.appspot.com/grafieken.jsp 谷歌应用程序引擎日志说错误在我页面的最后一行.这是一个nullpointerexception.

This page online: http://project-omega.appspot.com/grafieken.jsp The google app engine logs say the error is on the last line of my page. It's a nullpointerexception.

我不知道这意味着什么,我真的希望有人能帮助我.

I have no idea what it means and I really hope someone can help me.

非常感谢,抱歉我的英语水平.

Thanks a lot and sorry for my english.

编辑 呈现的输出如下所示

EDIT The rendered output looks as follows

  function drawChart() {
    var data = google.visualization.arrayToDataTable([                                               
      ['Beoordeling', 'Stage Opleider', 'Student'],
      for (Stelling s : alleStellingenLijst2) {
        out.println("['1', '" + s.getDeStelling() + "' , '" + s.getDeWaarde() + "'],");       
    }  
  ]);

新代码:

 function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Beoordeling', 'Stage Opleider', 'Student'],

          ['1', 1, 4],

          <%

            ArrayList<Stelling> alleStellingenLijst2 =(ArrayList<Stelling>) getServletContext().getAttribute("stellingen");
            for (Stelling s : alleStellingenLijst2) {
                out.println("['1', " + s.getDeStelling() + " , " + s.getDeWaarde() + "],");       
            }   
        %> 
        ['2', 2, 2]
        ]);

推荐答案

这些是JSP标记,您不能在JavaScript中使用它们!

These are JSP markups, you cannot use them in JavaScript!

这是因为JSP文件在编译过程中被编译为.java类,而JavaScript在客户端执行.

That's because JSP files are compiled to the .java classes during compilation, and JavaScript is executed on the client side.

您可以做相反的事情-在JSP文件中生成JavaScript代码,这样就可以将所需的一些数据传递给JS变量.

You could do the opposite - generate a JavaScript code in the JSP file, that way you could pass some data you want to the JS variables.

这篇关于在javascript函数中使用jsp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆