3

I am in the process of building a JSP based website using the Spring MVC framework and Bootstrap, and I have all of my separate web pages pretty much done. A little late in the game I've decided that I want to add a navigation bar to my website. I've created the navigation bar already but is there some easy way to "tack" it onto the other web pages easily so I don't have to duplicate code in separate files?

If I put the navigation bar HTML code in a separate file and include it on a JSP page, will it show up appropriately?

Is there a normal standard way people extend navigation bars to their whole website? I'm sure people who have experience creating websites should be able to easily answer this. I certainly appreciate any help that can be offered. Thank you!!!!

Tastybrownies
  • 897
  • 3
  • 23
  • 49

2 Answers2

4

Make a tag. Like navbar.tag in tags directory which will be in your WEB-INF dir. Add your code there and include it in desired JSP pages. To include your tags in JSP add this into a header:

<%@ taglib prefix="mytags" tagdir="/WEB-INF/tags" %>

And use your tag like this:

<html>

    <body>
        <mytags:navbar/>
    </body>
</html>
Branislav Lazic
  • 14,388
  • 8
  • 60
  • 85
2

You can use any Layout template framework such as Sitemesh or Tiles with Spring MVC. You need to add your navigation into the template layout (Master layout page) so your navigation bar will be displayed on any pages that referencing to the layout.

See this post: How do I integrate Sitemesh 3 with Spring MVC 3?

Other resources:

Community
  • 1
  • 1
LHA
  • 9,398
  • 8
  • 46
  • 85