Reage
Reage

Reputation: 21

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 ?

Upvotes: 1

Views: 1634

Answers (1)

Karol Dowbecki
Karol Dowbecki

Reputation: 44960

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" />

Upvotes: 1

Related Questions