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