I am using jsp for scripting. I have a page where I collect data from dropdown boxes and radio buttons and then form a query based on data inserted by the user.
I then hit the url(query here is append to a url i.e a query string) and in return I get an xml file.
I parse the file and formulate it in a particular way in a string which I need to pass it to a javascript function, that renders the graph based on passed values.
I wanted to know how/where should I call the javascript function and pass the JSP string to it so that it can render the graph.
I have tried putting it on OnClick event in the html form but I am not sure if it's the correct way of doing it. Please let me know how can I go about this porblem.
Form
I am using jsp for scripting. I have a page where I collect data from dropdown boxes and radio buttons and then form a query based on data inserted by the user.
I then hit the url(query here is append to a url i.e a query string) and in return I get an xml file.
I parse the file and formulate it in a particular way in a string which I need to pass it to a javascript function, that renders the graph based on passed values.
I wanted to know how/where should I call the javascript function and pass the JSP string to it so that it can render the graph.
I have tried putting it on OnClick event in the html form but I am not sure if it's the correct way of doing it. Please let me know how can I go about this porblem.
Form
Share Improve this question asked Mar 18, 2012 at 0:33 Ajinkya KarandeAjinkya Karande 1932 silver badges9 bronze badges1 Answer
Reset to default 6JSP cannot call JavaScript functions. JSP is a server side view technology which runs in the webserver and generates HTML/CSS/JS output. JavaScript is a client side scripting language which runs in webbrowser and works on HTML DOM tree.
You can however let JSP print JavaScript code accordingly so that it get executed in the webbrowser once the HTTP response arrives. E.g.
<script>someFunction('${someString}');</script>
Imagine that ${someString}
resolves to a string "foo"
, then when JSP runs, the webbrowser will retrieve the following:
<script>someFunction('foo');</script>
(rightclick page in browser and do View Source to see it yourself)
Once the webbrowser gets to that line, it will then execute the JS function with the string variable which is printed by JSP.
See also:
- Our JSP wiki page
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744354421a4570160.html
评论列表(0条)