This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See I have a JSP with an html form with an input onChange calling my javascript method. My javascript method calls a method in a java file (not a bean) and receives a return value just fine. My problem is that I now want to pass the value of the input field as a parameter to the java method. I know I'm mixing JSP & Javascript in an awful way... can anyone tell me a better way to do this? (I'm even cheating & using a jsp:include bean tag to be able to access)
...may the Java gods forgive me....
Author and ninkuma
Posts: 66424
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You realize that your Javascript is not "calling" the Java in your 'fake bean', don't you?
What is happening is that when the page is being rendered on the server, the values returned from your Java methods are being substitued in the Javascript text. (A 'view source' from the browser will confirm this).
So since your Java is not being called at 'client time', there's no way you can pass a client-side value to the methods.
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you rightly mention, you are mixing JSP and Java quite awfully.
Instead try this,
get the javascript to submit the form and when the form submits, get the variable and then call the java method from jsp
Hope this helps
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!