This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

how to call jsp method from html button form.

 
Ranch Hand
Posts: 62
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

try this code
according to your reqment
 
shahidrasul shahid
Ranch Hand
Posts: 62
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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 ]
 
Greenhorn
Posts: 2
  • 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.
 
Rancher
Posts: 43011
76
  • 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.
 
Ranch Hand
Posts: 42
  • 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... :-)
 
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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 ]
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!