Create Bootstrap template to be used on all JSP pages of your Java app, implementing only the "content / content"

1

Good morning,

Personal, "I know it's more of a subject", but someone could help me with this question.

I'm used to making templates with facelets, so I generate an xhtml file and write it down inside it, where it will be Header, Content and Footer. This way, in the other pages, I import the template through a tag.

My question is:

As I can do something similar, but using Bootstrap, I need to generate a main page, where it will have the template structure, and in the other pages of the project, I'll just implement the content, without having to rewrite everything the HTML code.

Note: I'm also searching the web but I had a lot of questions, so I wrote here.

Thank you.

    
asked by anonymous 24.05.2016 / 15:51

2 answers

0

You can also use taglibs, just add in the WEB-INF folder a folder for the content you want to create and then add small files with the tags themselves:

  • Create the WEB-INF / tags folder:
  • Inside it creates a file called header.tag

Add the code you want to use, for example:

<%@ attribute name="urlImage" required="true"%>
<nav class="navbar navbar-default">
   <div class="container-fluid">
      <div class="navbar-header">
         <a class="navbar-brand" href="#">
           <img alt="Brand" src="${urlImage}">
         </a>
      </div>
   </div>
</nav>

And in your jsp use it as follows:

<%@ taglib tagdir="/WEB-INF/tags" prefix="tag"%>
<tag:header urlImage="url/da/imagem"/>

And for others it's the same process.

    
24.05.2016 / 20:21
0

I solved the problem as follows:

1: The excerpts that would not change, for example the Menu, created a file called menu.jsp, and left only the menu code in the file.

On the home.jsp page, I imported the menu.jsp page.

menu.jsp: (Generate a blank file and just write the code of your menu), as it will be assigned to home.jsp.

home.jsp: (Here you should have the full header of a JSP)

Inside the body tag:

jsp:include page="template/menu.jsp"
    
24.05.2016 / 19:56