實現J2EE中後台action中控制前台javascript彈出對話方塊,j2eeaction

來源:互聯網
上載者:User

實現J2EE中後台action中控制前台javascript彈出對話方塊,j2eeaction

1、後台Action中:

request.setAttribute("message", "此使用者名稱或密碼錯誤,請從新輸入!");


2、前台jsp頁面中:

2.1、在<body>標籤中增加onload方法,比如:<BODY  topmargin="0" leftmargin="0" onload="checkForm()">

2.2、在本jsp頁面中加入js代碼塊,如下:

<!-- 彈出對話方塊:此使用者名稱或密碼錯誤,請從新輸入! -->
<script type="text/javascript">
function checkForm() { 
var flag = '<%=request.getAttribute("message")%>'; 
if(flag != "null") { 
alert(flag); 
/*清空<input>標籤中的值
$("#name").attr("value","");
$("#password").attr("value","");
*/
}
} 
</script>


總結:通過在後台將錯誤提示資訊放到message中,在前台jsp中通過調研onload方法執行js代碼彈出對話方塊。


怎將前台資料提交給action後,當action處理完後,用javascript彈出一個對話方塊,提示成功

得用ajax 。。你可以在網上找找。jquery的ajax 。很簡單。只要action的uri是對的就可以調用傳回值給介面上。。
 
JAVA怎在action中彈出JS對話方塊??

因為return 了。改成return null試下
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.