Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting javascript function value in a servlet  RSS feed

 
Mo Alexwainy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a servlet with a delete query.
Within the same servlet i have created a javascript function to confirm delete. However i am not able to pass the result of the function (true/false) to the servlet to further execute.
Any ideas?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets run on the server. JavaScript runs in the browser long after the servlet has finished running. So, you're never going to get JavaScript to send info to a servlet except by making a new request.

Summary:
  • the servlet runs on the server in order to generate an HTML page to send to the browser
  • the servlet stops running when the generated page is sent to the browser
  • the browser recevies the page and loads it
  • JavaScript on the page is loaded and executed by the browser


  • Note how the server and JavaScript code do not execute in the same context, and note how the JavaScript executes long after the servlet execution is dead and buried.

    I suspect that your app structure needs rethinking. Please see this article for information on how Java web applications are structured.
     
    Mo Alexwainy
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks.
    What would be the ideal coding to get a confirmation for deletion to proceed with the execution?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65826
    134
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You ask before you initiate the actual delete request. See the article I mentioned.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!