Using Jsp In Javascript Function
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
Solution 1:
These are JSP markups, you cannot use them in JavaScript!
That's because JSP files are compiled to the .java classes during compilation, 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.
Solution 2:
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:
@OverrideprotectedvoiddoGet(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() + "],");
}
}
%>
Post a Comment for "Using Jsp In Javascript Function"