By including a JSP page on another JSP page, how do I avoid multiple HEAD / BODY sections?

I would like to include the JSP page in another JSP page. Let's say that I have master.jspone that includes slave.jsp.

Since it slave.jsphas its own section <head>for working with JavaScript and CSS, is there a way, or possibly another method, to merge the section masterand slave HEAD into one? The same should be done for the BODY section .

I’ve been using sitemesh lately , but I think it’s not practical to set up a template for each page.

+3
source share
4 answers

, .

master.jsp

<head>
  blablabla
  <c:import url="slave.jsp">
    <c:param name="sectionName" value="HEAD" />
  </c:import>
</head>
<body>
  blablabla
  <c:import url="slave.jsp">
  </c:import>
</body>

slave.jsp .

<c:choose>
  <c:when test="${param.sectionName == 'HEAD'}">
     head section here [without the <HEAD> tags !]
  </c:when>
  <c:otherwise>
     body section here [without the <BODY> tags !]
  </c:otherwise>
</c:choose>

, . , HEAD BODY.

+2

<html> . . CSS/JS JSTL c:if c:choose.

:

<head>
    <script type="text/javascript" src="global.js"></script>
    <c:if test="${isAdminPage}">
        <script type="text/javascript" src="admin.js"></script>
    </c:if>
</head>
+1

sitemesh, . , , . ?

0

meta.jsp (), Map - , css hrefs, script hrefs jsp . request.getRequestURI() , . , .

0

Source: https://habr.com/ru/post/1724644/


All Articles