How to Hide a DIV in JSP HTML


HTML elements can be controlled by server-sided languages using conditional statements. A JSP script using an "if / else" statement can set the display property for the <div> tag before outputting the HTML to the user's computer. The variable value used in the "if" statement is easily passed in the URL to reflect the user's setting.

  • Open the JSP file for editing in your favorite script editor. If you are using a WYSIWYG editor, switch to view the source code.

  • Enter following code for an "if" statement that uses the URL passed variable to control the output:


    String hide = request.getParameter( "hide" );

    if( hide.equals( "true" ) )


    out.println("<a href='mypage.jsp?hide=false'> Show Section </a>");

    out.println("<div id='mydiv' style='display:none;'>");




    out.println("<a href='mypage.jsp?hide=true'> Hide Section </a>");

    out.println("<div id='mydiv' style='display:block;'>");



    The JSP code replaces the opening <div> tag. You need to replace "mypage" with the name of the file and the "div id" with the appropriate reference for your <div> tag.

  • Save the JSP file, then upload it to your Web server and preview it. As you click on the link to hide or show the <div> element, the page will be reloaded from the server with the appropriate display setting to either hide the element or show it as a block.

Tips & Warnings

  • You need to change only the opening <div> tag and the link controlling whether to hide or show the <div>. You do not need to replicate the remaining HTML for the content of the <div> and the closing <div> tag.


  • Photo Credit Comstock/Comstock/Getty Images
Promoted By Zergnet


You May Also Like

  • How to Hide a DIV Tag

    In HTML, "<div>" tags are used to separate out blocks of text, giving them unique styles or carefully positioning them on a...

  • How to Reference a CSS File From JSP

    How to Hide a DIV in JSP HTML. Using just hypertext markup language (HTML) and cascading style sheets (CSS), you can create...

  • How to Create a DIV With PHP

    How to Create a DIV With PHP. ... How to Hide a DIV in JSP HTML. HTML elements can be controlled by...

  • How to Hide an Object with CSS

    Other People Are Reading. How to Hide Contents of a Div With CSS; How to Hide CSS From IE

  • List of JSP Tags

    JSP tags are an essential part of Java Server Pages, ... JSP; Why Are There Gaps Between Div Tags? How to Use...

  • How to View a JSP File

    A Java Server Page file, more commonly known as a JSP file, ... How to Hide a DIV in JSP HTML. Open...

  • How to Hide a Link on a Web Page

    How to Hide a DIV in JSP HTML. Featured. The eHow Tech Holiday Gadget Guide. Check It Out. Unboxing the Logitech Harmony...

Related Searches

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!