aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes passing a value from Javascript to JSP method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "passing a value from Javascript to JSP method?" Watch "passing a value from Javascript to JSP method?" New topic
Author

passing a value from Javascript to JSP method?

zub kodi
Greenhorn

Joined: Jan 23, 2008
Posts: 5
Here is my code and below is my explanation?

javascript code....

I need to pass a selected value from the Form Dropdown into a java setMethod() in my jsp page. But I can't seem to figure out how? I used the "setValue" javascript funtion as shown above, that passes the value from Javascript to jsp on a onClick event, but it doesn't work. I did some research on the internet and have learnt that I cannot pass values from Javascript to jsp.

Is there any other method, may be after I hit the submit button? I need to pass the selected value from a student dropdown list to a jsp setMethod(). So for example if I select, Jon from a Dropdown list which has a ID = 5, then I need to pass 5 to the java method.

Any Clues?

Thanks
[ April 03, 2008: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Originally posted by zub kodi:
I need to pass a selected value from the Form Dropdown into a java setMethod() in my jsp page. But I can't seem to figure out how?

That's because you can't.
Any Clues?
Your JSP executes on the server in order to format the HTML page (including your script) to be sent to the client. By the time your JavaScript executes, the JSP has long since finished processing and has gone out of scope.

You might find this article helpful in understanding JSP concepts.
[ April 03, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

To communicate with the server after the page has been loaded, you either need to submit the page back to the server, or send a request to the server via Ajax. As you will realize after reading the linked article, you can't just call Java methods from script -- especially any methods in the JSP that created the page.

(And before anyone gets the bright idea of mentioning DWR, that's just a special case of Ajax and should not even be considered before thoroughly understanding how HTTP, JSP and the whole Ajax ball of wax works.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing a value from Javascript to JSP method?