Implement j2eeaction in the background action of J2EE to control the front-end javascript pop-up dialog box

Source: Internet
Author: User

Implement j2eeaction in the background action of J2EE to control the front-end javascript pop-up dialog box

1. In the background Action:

Request. setAttribute ("message", "this user name or password is incorrect. Please enter a new one! ");


2. Front-end jsp page:

2.1 Add the onload method to the <body> label, for example, <BODY topmargin = "0" leftmargin = "0" onload = "checkForm ()">

2.2 Add the js Code block to the jsp page as follows:

<! -- Dialog box: the user name or password is incorrect. Please enter a new one! -->
<Script type = "text/javascript">
Function checkForm (){
Var flag = '<% = request. getAttribute ("message") %> ';
If (flag! = "Null "){
Alert (flag );
/* Clear the value in the <input> label
$ ("# Name"). attr ("value ","");
$ ("# Password"). attr ("value ","");
*/
}
}
</Script>


Conclusion: The error message is put into the message in the background, and the js Code Execution dialog box is displayed in the front-end jsp by investigating the onload method.


After the Foreground Data is submitted to the action, after the action is processed, a dialog box is displayed in javascript, prompting that the operation is successful.

Use ajax .. You can search for it online. Jquery ajax. Very simple. You can call the return value to the interface as long as the uri of the action is correct ..

How does JAVA pop up the JS dialog box in action ??

Because return is returned. Change to return null. Try again.

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.