java - Good JSP code structure for header and footer -
i have following code structure of jsp pages:
mypage.jsp
<jsp:include page="header.jsp"/> specific page content <jsp:include page="footer.jsp"/>
however, means header , footer code not have correct html structure. example, simplified header , 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 result, ide gives warning "missing start tag" / "missing end tag". don't feel disabling warning entirely since may find legitimate issues html structure.
is there cleaner way structure jsp code can still reuse header , footer code in way?
might helpful. please have look.
\home.jsp // base page \parts\meta.jsp // hold page meta information. useful when working seo \parts\header.jsp // resources css, images, \parts\footer.jsp // resources js
remember
use <%@include> because static include , <jsp:include> dynamic include. when use <jsp:include> file included @ runtime. when use <%@include> file included @ compile time.
so here code snippet.
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>
thanks :)
Comments
Post a Comment