File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to call jsp method from html button form.

 
shahidrasul shahid
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to call jsp / java method when i click on the button.please any body tell me immediately.
thanks advance.
 
mahesha
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

try this code
according to your reqment
 
shahidrasul shahid
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic