简体   繁体   English

在整个Spring MVC / JSP应用程序中显示导航栏

[英]Display Navigation Bar Throughout Spring MVC/JSP Application

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. 我正在使用Spring MVC框架和Bootstrap构建基于JSP的网站,我已经完成了所有单独的网页。 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? 如果我将导航栏HTML代码放在一个单独的文件中并将其包含在JSP页面中,它是否会正确显示?

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!!!! 谢谢!!!!

Make a tag. 制作标签。 Like navbar.tag in tags directory which will be in your WEB-INF dir. 就像tags目录中的navbar.tag一样,它将在你的WEB-INF目录中。 Add your code there and include it in desired JSP pages. 在那里添加代码并将其包含在所需的JSP页面中。 To include your tags in JSP add this into a header: 要在JSP中包含标记,请将其添加到标题中:

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

And use your tag like this: 并像这样使用你的标签:

<html>

    <body>
        <mytags:navbar/>
    </body>
</html>

You can use any Layout template framework such as Sitemesh or Tiles with Spring MVC. 您可以使用任何布局模板框架,例如Sitemesh或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? 看这篇文章: 如何将Sitemesh 3与Spring MVC 3集成?

Other resources: 其他资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM