简体   繁体   中英

window.confirm() in java servlet

In web app I want to get an answer to questions in servlet;

PrintWriter out1 = response.getWriter();  
            response.setContentType("text/html");  
            out1.println("<script type=\"text/javascript\">");  
            out1.println("confirm('question?');");  
            out1.println("</script>");

this code give me a confirm dialog , but i dont know how to get the answer of it in servlet

Is there is a possible way?

The servlet is server side code. is The confirm is client side, in the browser. It returns true or false depending on what button the user clicks. You need to capture that result in javascript in the browser and send it to the server for the servlet to see.

If you have a series of questions then you might be best to use a form, rather than the confirm dialog. Multiple confirm dialogs gives a really bad user experience. In your servlet response you would create a html form, and then inside the form create an input for each question. The form also provides a ready made way to submit the results back to your servlet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM