Summary of the JSP pop-up dialog box

Source: Internet
Author: User

In the process of interacting with users, a prompt box is sometimes required to notify users of some information, such as incorrect logon password.

In the JSP web page project, three effective methods are put into practice and summarized.

Method 1: JSP front-end

<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Alert ("You have not logged on, please log on ...");
Required parameter Doc ument. Location. href = "userlogin.html ";
</SCRIPT>

Method 2: Java background

Public void popalert (){

Response. setcharacterencoding ("UTF-8 ");
Printwriter out = response. getwriter ();
Out. Print ("<SCRIPT> alert ('you have not logged on, please log on... '); Using location='userlogin.html' </SCRIPT> ");
Out. Flush ();
Out. Close ();

}

Method 3: Java background+JSP front-end

1) Java background code segment

Public void popalert (){

Request. setattribute ("loginerror", "You have not logged on, please log on..."); // set the error attribute
Request. getrequestdispatcher ("userlogin.html"). Forward (request, response );

}


2) JSP front-end code segment

<%
String errorinfo = (string) request. getattribute ("loginerror"); // get error attributes
If (errorinfo! = NULL ){
%>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Alert ("<% = errorinfo %>"); // the error message is displayed.

Window.location='userlogin.html '; // jump to the logon page
</SCRIPT>
<%
}
%>

Summary

Bytes


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.