0

I have a message that I am pushing from the controller to the JSP. I want to check if the message is not null then display it to the JSP page for a minute.

This is my controller snippet

ModelAndView mav = new ModelAndView("dashboard");
                        mav.addObject("message", "Login Successful");
                        return mav;

I am using it in the view as shown this way

<h4 align="center">${message} </h4>

How can I display it for an interval of a minute?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
blend
  • 59
  • 1
  • 7

2 Answers2

0

You can do it in javascript call every minute to your controller which will be in function e.g. callController():

<script type="text/javascript">
   setTimeout(function(){ callController() }, 60000);
</script>

*60000 - is minute in milliseconds

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

You can use javascript's setTimeout method to call a callback function that can hide the text after 1 minute.

  • Assign an id to you H4 tag <h4 align="center" id="msgid">${message} </h4>
  • Set timeout on body on load <script type="text/javascript"> setTimeout ( "doSomething()", 60000 );</script>
  • Inside doSomething() method write javascript code to hide the text.

    function doSomething(){ document.getElementById('msgid').innerHTML=''; }

mkalsi
  • 355
  • 1
  • 3
  • 14
  • please refer https://stackoverflow.com/questions/3842614/how-do-i-call-a-javascript-function-on-page-load post for calling a javascript code on page load. – mkalsi Sep 18 '17 at 10:46
  • where do I attach this >>>

    ${message}

    – blend Sep 18 '17 at 10:49
  • you can assign an id to you h4 tag

    ${message}

    On body load call function function doSomething ( ) { document.getElementById('msgid').innerHTML=''; //this code will clear you msg }
    – mkalsi Sep 18 '17 at 11:15
  • please edit your answer to include the comments. tnx – blend Sep 18 '17 at 11:41