• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Getting javascript function value in a servlet  RSS feed

 
Greenhorn
Posts: 24
  • 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?
 
Author and ninkuma
Marshal
Posts: 66789
168
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: 24
    • 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: 66789
    168
    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!