簡體   English   中英

如何從Java servlet到HTML頁面生成警報框?

[英]How to generate an alert box from java servlet to a HTML page?

upwd->在名為(index.html)的HTML頁面中引用登錄頁面中輸入的密碼

rpwd->在同一HTML頁面的登錄頁面中引用重新輸入的密碼

    //-->Code in servlet
    if(upwd.equals(rpwd))
     {
           //database connectivity of a login form 
     }
    else
     {
         response.sendRedirect("index.html");
          //index.html is the name of the html page where im redirecting. 
     }

由於我正在servlet中進行驗證。現在,如何在HTML(index.html)中生成一個警告框,說明密碼與Servelet不匹配。

從這里有兩種方法可以生成帶有消息的alert

第一種方法 :將下面的html代碼放入index.html文件中

alert("password didn't matched !");

第二種方法:從servlet生成警報,然后重定向到HTML頁面

 out.println("<script type=\"text/javascript\">");
 out.println("alert('password didn't matched ');");
 out.println("</script>");
 response.sendRedirect("index.html"); 

您甚至可以閱讀: 如何在servlet的jsp中顯示警報,然后重定向到另一個jsp? 希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM