Good JSP code structure for header and footer

Currently, I have the following code structure for my JSP pages:

Mypage.jsp

<jsp:include page="header.jsp"/>
Specific page content
<jsp:include page="footer.jsp"/>

However, this means that the header and footer code does not have the correct HTML structure. For example, this is a simplified header and footer code:

header.jsp

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>${param.pageTitle}</title>
    </head>
    <body>
        <div class="container" style="margin-top: 80px;">

footer.jsp

        </div>
    </body>
</html>

As a result, the IDE issues a warning about the "missing start tag" / "Missing end tag". I don’t feel good about disabling the warning completely, as it might find legitimate problems with the HTML structure.

Is there a cleaner way to structure the JSP code so that I can use the header and footer code again somehow?

+4
2

, . , .

\home.jsp               // Base Page
\parts\meta.jsp         // To hold page meta information. Useful when working with SEO
\parts\header.jsp       // Resources CSS, images, 
\parts\footer.jsp       // Resources JS

Use <%@include> because it is static include and <jsp:include> is dynamic include. When you use <jsp:include> the file will be included at runtime. When you use <%@include> file will be included at compile time.

, .

1) home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="parts/meta.jsp" %>  
<title>Home Page</title>
<%@ include file="parts/header.jsp" %>  
</head>
<body>
    <div class="view">
        <div class="pages">
            <jsp:include page="parts/page-body.jsp"></jsp:include>
        </div>
    </div>
    <%@ include file="parts/footer.jsp" %>  
</body>
</html>

2) meta.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta charset="utf-8">
<meta name="viewport"
    content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

3) header.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link href="http://fonts.googleapis.com/css?family=Roboto:400,300,500,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/my-page.css">
<link rel="stylesheet" href="css/my-icon.css">
<link rel="icon" href="img/icon.png">

4) footer.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script type="text/javascript" src="js/my-app.js"></script>
<script type="text/javascript" src="js/my-app-service.js"></script>

:)

+4

, , . include, . . , jsp jsp, . MyPage.jsp : -

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>${param.pageTitle}</title>
    </head>
    <body>
         <jsp:include page="header.jsp"/>
             Specific page content
         <jsp:include page="footer.jsp"/>
    </body>
</html>

header.jsp footer.jsp : -

<!DOCTYPE html>
<html lang="en">
    <head>
    </head>
    <body>
          Specific page content
    </body>
</html>

.

-7

All Articles