Examples of usages of JSP---three popup dialog boxes

Source: Internet
Author: User

(Non-original)

Way 1:jsp Front End

<script type= "Text/javascript" language= "JavaScript" >
Alert ("You are not logged in, please log in ...");
Window.document.location.href= "userlogin.html";
</script>

Way 2:java Backstage

public void Popalert () {

Response.setcharacterencoding ("Utf-8");
PrintWriter out = Response.getwriter ();
Out.print ("<script>alert (' You are not logged in, please login ... '); window.location= ' userlogin.html ' </script> ');
Out.flush ();
Out.close ();

}

Way 3:java Backstage   +   JSP frontend

1) Java Background Code snippet

public void Popalert () {

Request.setattribute ("LoginError", "You are not logged in, please login ..."); Setting Error Properties
Request.getrequestdispatcher ("userlogin.html"). Forward (request, response);

}

2) JSP frontend code snippet

<%
String errorinfo = (string) request.getattribute ("LoginError"); Get Error properties
if (errorinfo! = null) {
%>
<script type= "Text/javascript" language= "JavaScript" >
Alert ("<%=errorInfo%>"); Pop-up error message

window.location= ' userlogin.html '; Jump to login screen
</script>
<%
}
%>

Summarize

Three ways, essentially through the JavaScript popup dialog box, prompting the user password error, when the user clicked the Alert OK button, automatically jump to the login interface userlogin.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.