• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

calling java code from javascript in jsp file

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
thanks a lot, I did it with ajax as you suggested.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic