Pass Javascript Value to Java in JSP - Stack Overflow

I would like to pass a Javascript value to a Java function in JSP. How can I do that?The id es from a

I would like to pass a Javascript value to a Java function in JSP. How can I do that? The id es from a bobox in JSP via Javascript. I will get the ID from ComboBox and send it to Java function as parameter to get the Java result.

function Display()
{
   var IdFromCB = (document.getElementById("MListSelect")).value;
   //CALL JAVA FUNCTION HERE BY USING IdFromCB as function parameter
   //'<% getSomething(-----IdFromCB-----);%>'

}

Thanks,Mark

I would like to pass a Javascript value to a Java function in JSP. How can I do that? The id es from a bobox in JSP via Javascript. I will get the ID from ComboBox and send it to Java function as parameter to get the Java result.

function Display()
{
   var IdFromCB = (document.getElementById("MListSelect")).value;
   //CALL JAVA FUNCTION HERE BY USING IdFromCB as function parameter
   //'<% getSomething(-----IdFromCB-----);%>'

}

Thanks,Mark

Share Improve this question edited Dec 19, 2013 at 9:29 Struggling Developer 2951 gold badge3 silver badges15 bronze badges asked Dec 19, 2013 at 9:25 Mark KaranMark Karan 1692 gold badges5 silver badges16 bronze badges 1
  • Karan, Please go through the lifecycle of JSP to better understand why it is not possible. – Batakj Commented Dec 19, 2013 at 9:31
Add a ment  | 

2 Answers 2

Reset to default 7

You cannot make a server call directly. You need to make a server request.

javascript plays on client side and JSP plays on server side.

What you need is you have to make a server request. And send that string as a query parameter.

Two options to achieve this.

  • HTML forms
  • Ajax.

Do not confuse that JSP and java script existed on same document(or file). Yes but JSP part piles on server side and JavaScript executes by browser.

Javascript statements are rendered by Browsers and executed as client program.

In your case if you want execute a java code based on selection of html ponent, you would need to use ajax call .

You can find quick example here

A Simple AJAX with JSP example

http://www.programming-free./2013/03/ajax-fetch-data-from-database-in-jsp.html

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743734847a4498068.html

相关推荐

  • Pass Javascript Value to Java in JSP - Stack Overflow

    I would like to pass a Javascript value to a Java function in JSP. How can I do that?The id es from a

    7天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信