javascript
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 弹出对话框的方式总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 链表-单向链表的实现
- 下一篇: 基于javaweb的学籍管理系统计算机专