1、后臺(tái)Action中:
request.setAttribute("message", "此用戶名或密碼錯(cuò)誤,請(qǐng)從新輸入!");
2、前臺(tái)jsp頁(yè)面中:
2.1、在<body>標(biāo)簽中增加onload方法,比如:<BODY topmargin="0" leftmargin="0" onload="checkForm()">
2.2、在本jsp頁(yè)面中加入js代碼塊,如下:
<!-- 彈出對(duì)話框:此用戶名或密碼錯(cuò)誤,請(qǐng)從新輸入! -->
<script type="text/javascript">
function checkForm() {
var flag = '<%=request.getAttribute("message")%>';
if(flag != "null") {
alert(flag);
/*清空<input>標(biāo)簽中的值
$("#name").attr("value","");
$("#password").attr("value","");
*/
}
}
</script>
總結(jié):通過(guò)在后臺(tái)將錯(cuò)誤提示信息放到message中,在前臺(tái)jsp中通過(guò)調(diào)研onload方法執(zhí)行js代碼彈出對(duì)話框。