Display Navigation Bar Throughout Spring MVC/JSP Application - java

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

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>

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:
http://codesilo.wordpress.com/2013/07/11/spring-mvc-with-sitemesh-3/

Related

Vaadin 14 show simple HTML Page

I made some kind of internal manual for a webapp that i am developing. I am using Spring Boot and Vaadin 14. How to implement a button that shows that document? The html doc is in my resources folder. I wonder if i am stupid. Or should i write my own controller for this?
A Vaadin application itself is a single dynamic HTML page.
The easiest way to include HTML formatted content (not an HTML document) is to use the Html component.
Html html = new Html("<div><h3>Title</h3><p><b>Bold summary text</b></p><p>Other text</p></div>");
layout.add(html);
Note, when you use the Html component, you need to strip the <head> and <body> tags, as Html's purpose is not to show full HTML documents. The Html component's content should be included inside a single root element - usually a <div> is used for this purpose.
However, based on your use case, I think the Html component will serve you well.

JSP Template in other file - Spring Boot

I'm making a web application in spring boot. I have a lot of views created in JSP, but every view has the same footer and the same menu. Of course I can just copy all menu and footer code and paste it to 30 JSP but I would like to do somethink like this: I have file in which I have something like that menu="HTML CODE WITH MENU", and then in JSP in body section I just put {menu}, and all HTML code is put inside JSP. When I want to change my menu I will just change its code in "menu" variable/string or whatever it will be, and menu in all JSP will change. I tried a few solutions for example with include but it doesn't work. I search scritly the solution I have mentioned. Has anybody got any ideas how I can do this ?
Since you are using JSP you can use the standard JSTL <c:import> tag as explained here. The other options would be to use <%# include #> or <jsp:include>, either of them will work for local files:
<jsp:include page="footer.jsp" />
<%# include file="footer.jsp" %>
<c:import url="footer.jsp" />

integrating html design to servlet

I have a working servlet code, which processes some command prompt commands and I have an editor code written in html, now I want to add this html file to servlet. How do I do it? tried moving the html file to WEB-INF.
I've looked into this link on How to integrate HTML design into Servlet? but everything seems damn cumbersome as I have a very large html file.
Any other fixes?
If your editor.html contains only static JS, CSS and HTML (you don't depend on the data provided by your servlet), you can simply forward your servlet into JSP and include your html page from it using
<%# include file="editor.html" %>

Including the JQuery file in JSP confusion?

I have a JSP page called main.jsp and the jsp page has three iframes.
Each Iframe loads an individual JSP(page1.jsp , page2.jsp , page3.jsp) and each JSP uses a individual JS file consists of JQuery code.
Currently I included the Jquery 1.9.1.js in every JSP page ( main.jsp and it's iframe laded JSP's ) and my project works fine .
Is this the proper way , Because I included the Jquery 1.9.1.js in every JSP .
How I can load the Jquery 1.9.1.js in my main.jsp alone and make visible to all JSP's .
I don't want to include the Jquery 1.9.1.js in every JSP's . I need the Jquery 1.9.1.js to be centralized.
Is this possible ?
Hope my question is little clear and understandable.Please don't hesitate to edit or ask questions.
I dont think it is possible when you use iFrames.
Since each iframe src will load the new page and it runs in its own window context
Its not easy to use a single jQuery.js to control the behaviour for the controls inside iFrame.
So you did correct.
Still if you want, you could use different <div> and load the content into it. This way one jQuery will work, since all the divs are in same window context
While using iframes you have to add jquery in each page.Each page in iframe is considered as child.If you were using divs in place of iframe then using centralized jquery1.9.1.js would have worked.
I think you should make templates Header.jsp and Footer.jsp. Then included the Jquery 1.9.1.js on header or footer.
Then you can use header or footer on your main.jsp and on every page.

How to search the correponding JSP file of any web page/HTML page?

I have a web application . When i right click on any html/webpage inside my browser , for some pages it shows the excaxt jsp page like
http://localhost:8080/MyWebApp/vustomer.jsp while for some pages it shows action class instead of jsp page like
http://localhost:8080/MyWebApp/TellerAction.do?actionCode=3&page=controlPanel. I am not getting what is reason behind these two different
behaviour? i mean why it does show jsp file name for some page but not for others?
I guess because HTML code of page sometimes has <a href='...jsp'>...</a> and other times it has <a href='...do'>...</a>.
Your best bet to find out why is to ask author of code :)
Usually, .do URLs are served by servlets, not jsp.

Categories