简体   繁体   English

执行jsp脚本后调用javascript函数

[英]calling javascript function after jsp script execution

I am using jsp for scripting. 我正在使用jsp编写脚本。 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 ie a query string) and in return I get an xml file. 然后,我点击url(查询在这里追加到url,即查询字符串),并返回一个xml文件。

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. 我解析该文件,并以一种特殊的方式将其表达为字符串,我需要将其传递给javascript函数,该javascript函数根据传递的值来呈现图形。

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. 我想知道如何/在何处调用javascript函数并将JSP字符串传递给它,以便它可以呈现图形。

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. 我已经尝试将其放在html表单的OnClick事件中,但是我不确定这是否是正确的方法。 Please let me know how can I go about this porblem. 请让我知道如何解决这个问题。

Form 形成

JSP cannot call JavaScript functions. JSP无法调用JavaScript函数。 JSP is a server side view technology which runs in the webserver and generates HTML/CSS/JS output. JSP是一种在服务器中运行并生成HTML / CSS / JS输出的服务器侧视图技术。 JavaScript is a client side scripting language which runs in webbrowser and works on HTML DOM tree. JavaScript是一种客户端脚本语言,可在Web浏览器中运行并在HTML DOM树上运行。

You can however let JSP print JavaScript code accordingly so that it get executed in the webbrowser once the HTTP response arrives. 但是,您可以让JSP相应地打印JavaScript代码,以便在HTTP响应到达后在Web浏览器中执行它。 Eg 例如

<script>someFunction('${someString}');</script>

Imagine that ${someString} resolves to a string "foo" , then when JSP runs, the webbrowser will retrieve the following: 假设${someString}解析为字符串"foo" ,然后在运行JSP时,Web浏览器将检索以下内容:

<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. Web浏览器到达该行后,它将使用由JSP打印的字符串变量执行JS函数。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM