• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP/Javascript/Java together...

 
Gail Schlentz
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know, I know - I've read all the threads saying this can't / shouldn't be done... but I'll ask anyways.
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....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
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.
hth,
bear
 
Raghunandhan Ramanujam
Greenhorn
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
Raghu
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!