Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I asynchronously show/hide div in JSP using Java

I want to programmatically show a div tag after some processing has completed while rendering a JSP. What's the best way to do this using Java? Using jQuery I would do this:

$('#mydiv').removeClass("hide_me");

...or...

$('#mydiv').show();

How can I do this programmatically in Java while rendering the page?

like image 750
Brian Avatar asked Feb 13 '26 23:02

Brian


1 Answers

Assuming you have the standard JSP setup including JSTL and have mapped it to 'c' you could just do:

<c:if test="${myCondition}">
  <div id="mDiv">
    content
  </div>
</c:if>

It does seem from the comments like there is some confusion about rendering JSP on the server vs rendering content in the browser. Everything that happens in the JSP is server side work that has to completely finish before the browser receives the generated document and starts drawing it. You can't use JSP to change content that is already on the user's screen. You need javascript, html5, etc, for that.

like image 149
Affe Avatar answered Feb 15 '26 13:02

Affe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!