Search code examples
javascriptjavajqueryjspjsp-tags

How To Hide an HTML object in JSP?


i want know if there is a way to hide html objects in jsp..for e.g., i have a homepage with login and register button in my jsp app.I want to hide them after successful login.

here is the of screenshot of my homepage
https://i.sstatic.net/LxVkX.jpg


Solution

  • There are many of ways you can implement that.Couple of them would be

    1. If you are reloading the whole page when user has successfully logged in, you can use JSTL to selectively render components.

    ie, something like below.

      <c:if test="if_user_has_not_logged_in">
           <!-- HTML code for login and register button goes here-->
      </c:if>
    
    1. you can hide html components using simple Javascript as well By setting Style-> display as none. something like below

        //You invoke this code when user is logged in
        if('successfully_logged_in') {
         document.getElementById("divIdGoesHere").style.display = "none";
       }