i want to call jsp method from button not jsp file please tell me how to call jsp method not jsp file.
Can you explain in a little more detail what it is that you're trying to do? Your question doesn't make a lot of sense. By the time a button in a web page is drawn, the JSP has finished executing. [ February 22, 2008: Message edited by: Ben Souther ]
rupal patel
Greenhorn
Joined: Feb 21, 2008
Posts: 2
posted
0
Hi Shahid, You can do so by following way 1. write your java function inside java tag 2. write javascript tag and make a function with calling previous java function inside. Means a javascript function calls Java function 3. Call javascript function on onclick properties of button.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35220
7
posted
0
Originally posted by rupal patel: You can do so by following way
...
No. JavaScript can't call Java - they don't even execute on the same machine (JavaScript executes in the web browser, while the Java code runs in the JSP on the server). As Ben pointed out, they don't run at the same time, either. There may be ways to accomplish what shahidrasul is asking, but we'd need to know more about what exactly that is.
On click of the button, write a javascript function named testJava() and inside this javascript function, give your variables like var result = "call your method (displayResult) within expression tag"; if you want to see your output, just give alert(result); Then it will display the result what you got from java method.
Here when you click on the button, it will alert you the value returning from the displayResult() method.
Originally posted by Gayathri Chowduru: Hey, javascript can call the Java function.
No, it cannot. And your example shows nothing of the kind.
When you invoke a Java method in a JSP page, it executes the method on the server and embeds the result in the output. Whether this is embedded in JavaScript template text or not is completely irrelevant.
After the page is constructed and sent to the browser and the JavaScript executes, it has no knowledge that any output was written by a Java method. It's all just text at that point. The JavaScript is most certainly not calling the Java function which executed long ago and on the server.
You really need to read this article to understand how JSP really works. [ February 25, 2008: Message edited by: Bear Bibeault ]