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

Asked

Viewed 2,108 times

1

Good morning,

Guys, "I know it’s more of a subject of the same," but could someone help me with that question.

I’m used to making templates with facelets, so I write down a xhtml file inside it, where it will be Header, Content and Footer. That way, on 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 will have the structure of the template, and in the other pages of the project, I will just implement the contents, without need to rewrite all the HTML code.

Obs: I am also searching on the web but I had many doubts, so I wrote here.

Thank you.

  • Everton, the site works different than a forum. If you have found an answer, you can answer the question (as you have already done) and then mark it as accepted by clicking on V the left of the answer. This validates a question as "solved" here in Sopt.

2 answers

1


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

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

And in it add the code you want to use, 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.

  • Cool Nelson, thanks, thanks for the tip.

0

I solved the problem as follows:

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

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

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

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

Inside the tag body:

jsp:include page="template/menu.jsp"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.