java background output popup box to foreground

There are two implementation methods:


1. Print the js dialog box directly in the background, the principle is as follows:


    response.setContentType("text/html; charset=UTF-8"); //Transcoding
    PrintWriter out = response.getWriter();
    out.flush();
    out.println("<script>");
    out.println("alert('This username already exists, please re-enter!');");
    out.println("history.back( );");
    out.println("</script>");
    return mapping.findForward("");


Second, store a variable message in the background, the value of which is the content in the pop-up dialog box, and receive this in the foreground Variables, first of all put a hidden field in the front page, the value of the hidden field is empty when you visit the page for the first time, here you need to use onload to call js to pop up a dialog box, and the content in the background will pop up in the form of a dialog box, as follows:


Backstage:


request.setAttribute("message", "This username does not exist, please confirm and then enter!");


Frontstage:


<script type="text/javascript">
    function checkForm(){
     var flag=true;
     var message=form1.message.value;
     if(message!='null'){
      alert(message);
      flag=false;
     }
     return flag;
    }


</script>


 <body class="backgdcolor" onload="checkForm()">


<input type="hidden" name="message" value="<%=request.getAttribute("message") %>">


</body>


出处:http://blog.163.com/yurong_1987@126/blog/static/4751786320092711596354/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326647133&siteId=291194637