• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling Java Class method from JS  RSS feed

 
Nalini Nagarathinam
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having the JSP which contains the javascript, i would like to pass the variable of JS to Java method.

How to calll the java method from JS?

Thanks in advance.
 
aruna sydu
Ranch Hand
Posts: 98
MyEclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nalini Nagarathinam wrote:Hi,

I am having the JSP which contains the javascript, i would like to pass the variable of JS to Java method.

How to calll the java method from JS?

Thanks in advance.


Hi Nalini,

You can pass the variable of the javascript to JSP by appending the variable and its value as a queryString to the URL eg:http://URL&javascriptVariable=value. that you are using to submit to the class where you want to access the variable in the method.However you need to have access to the request object in the method where you want to access the variable like request.getParameter("javascriptVariable")


This might be one of the approches.
Hopes this helps

Aruna.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nalini Nagarathinam wrote:I am having the JSP which contains the javascript, i would like to pass the variable of JS to Java method.

Impossible. Please read this article to find out why.
 
Vinoth Thirunavukarasu
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way to do this by create new request to server..


Try posting form or using Ajax.......
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's clear that the poster is asking about passing JavaScript data to a method in the same JSP. The article points out why this is clearly impossible. (Aside from the fact that it's unbelievable that people are still putting Java code in JSPs! )
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can go through this framework which may help you do this ..

Direct Web Remoting

dwr is an ajax framework for jsp developers ...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DWR is an Ajax framework for Java developers, really--it doesn't matter what the presentation layer is as long as you can execute JavaScript in it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!