File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how to call jsp method from html button form. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to call jsp method from html button form." Watch "how to call jsp method from html button form." New topic
Author

how to call jsp method from html button form.

shahidrasul shahid
Ranch Hand

Joined: Jan 28, 2008
Posts: 62
how to call jsp / java method when i click on the button.please any body tell me immediately.
thanks advance.
mahesha
Greenhorn

Joined: Jul 23, 2007
Posts: 9

try this code
according to your reqment
shahidrasul shahid
Ranch Hand

Joined: Jan 28, 2008
Posts: 62
originnally by shahid

i want to call jsp method from button not jsp file please tell me how to call jsp method not jsp file.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"mahesha",
Please check your private messages.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by shahidrasul shahid:

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
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: 42913
    
  68
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.
Gayathri Chowduru
Ranch Hand

Joined: Oct 17, 2007
Posts: 42
Hey, javascript can call the Java function. Here I am giving you an example. :-)

Write your method inside the declaration tag which is

public String displayResult(){
retrun "IBM";
}

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.

Let me know if you have any concerns... :-)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to call jsp method from html button form.