• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling java code from javascript in jsp file  RSS feed

 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a jsp file in which I have a few controls. I want the user to fill them , to click on a button that invokes a javascript function.
The javascript function should print on the screen the result of the jsp code:
function go()
{
<% out.println(my java code that returns string); %>
}
I can see the java result only from the page source - I right click on the page -> view -> source
and then I can see the result of the java code located instead of the : <% out.println(my java code that returns string); %>.

Even more - if I write in go() function only document.write("hello"); , the print "hello" will be to the souce of the page and no one
can see it. why ??? it should write hello on the screen.

I hope I managed to describe the question. sorry if not...
Thanks in advance.

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't work that way. The Java/JSP code runs on the server, not on the client. So whatever happens in the HTML/JavaScript, it can't involve Java/JSP code.

If you need to evaluate Java code from within an HTML page, then you may want to look into AJAX solutions that can access a piece of server code from within JavaScript code.
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
thanks a lot, I did it with ajax as you suggested.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!