日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

JSP 弹出对话框的方式总结

發布時間:2024/1/1 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JSP 弹出对话框的方式总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

JSP 網頁在與用戶交互的過程中,有時需要彈出提示框,通知用戶一些信息,如登錄密碼錯誤等

在做JSP網頁項目中, 實踐并總結了三種有效的方式

?

方式1: JSP前端

<scripttype="text/javascript" language="javascript">

alert("您還沒有登錄,請登錄...");

window.document.location.href="userlogin.html";

</script>

?

方式2: Java后臺

public void popAlert() {

response.setCharacterEncoding("utf-8");

PrintWriter out =response.getWriter();

out.print("<script>alert('您還沒有登錄,請登錄...');window.location='userlogin.html' </script>");

out.flush();

out.close();

}

?

方式3:Java后臺? + ?JSP前端

1 Java后臺代碼段

public void popAlert() {

request.setAttribute("loginError","您還沒有登錄,請登錄..."); ? ????? ?//設置錯誤屬性

request.getRequestDispatcher("userlogin.html").forward(request,response);

}

?

2 JSP前端代碼段

<%

String errorInfo =(String)request.getAttribute("loginError");????????// 獲取錯誤屬性

if(errorInfo != null) {

%>

<scripttype="text/javascript" language="javascript">

alert("<%=errorInfo%>");? ? ? ? ??? ? ? ? ?? ? ? ? ? ? ? ? ???? ?// 彈出錯誤信息

window.location='userlogin.html'; ? ? ? ? ? ? ? ? ? ???? ? ?// 跳轉到登錄界面

</script>

<%

}

%>

?

?

總結

三種方式,實質都是通過JavaScript彈出對話框,提示用戶密碼錯誤,當用戶點擊alert確定按鈕后,自動跳轉到登錄界面userlogin.html

?

?

原文地址:http://blog.csdn.net/sunboy_2050/article/details/8033002

總結

以上是生活随笔為你收集整理的JSP 弹出对话框的方式总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。