admin管理员组文章数量:1315258
I've searched for this but can't find anything. Please correct my question if it's incorrect english.
This is my code: EDIT: 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 petenties',
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);
}
For some reason, it wont execute the code between the <% %> (from the jsp).
This page online: .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() + "'],");
}
]);
NEW CODE:
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]
]);
I've searched for this but can't find anything. Please correct my question if it's incorrect english.
This is my code: EDIT: 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 petenties',
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);
}
For some reason, it wont execute the code between the <% %> (from the jsp).
This page online: http://project-omega.appspot./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() + "'],");
}
]);
NEW CODE:
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]
]);
Share
Improve this question
edited Oct 31, 2013 at 14:10
Colinch
asked Oct 31, 2013 at 13:27
ColinchColinch
3532 gold badges7 silver badges22 bronze badges
2 Answers
Reset to default 4These are JSP markups, you cannot use them in JavaScript!
That's because JSP files are piled to the .java classes during pilation, and JavaScript is executed on the client side.
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.
I suppose you haven't set the stellingen
request attribute.
You usually set the request attributes in a servlet, before forwarding the request to jsp:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
ArrayList<Stelling> list = ...;
req.setAttribute("stellingen", list);
req.getRequestDispatcher("/grafieken.jsp").forward(req, resp);
}
Also make sure the attribute is set in the JSP code:
<%
List<Stelling> stellingen = (List<Stelling>) getServletContext().getAttribute("stellingen");
if(stellingen == null) {
out.println("stellingen attribute not set!");
}else{
for (Stelling s : stellingen) {
out.println("['1', " + s.getDeStelling() + " , " + s.getDeWaarde() + "],");
}
}
%>
本文标签: javausing jsp in javascript functionStack Overflow
版权声明:本文标题:java - using jsp in javascript function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741962091a2407337.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论