Basic JSP Templates
There is a very basic choice for templating creation with JSP based on “includes. It could be useful to response quickly to a client, very little project, avoid to use heavy technologies, or we want to deploy our project on every application server.
The technique creates little JSP code chunks for header and footer. After create all pages from a template.
With our Eclipse go to New … > Dynamic Web Project, we will call basic_templating
The basic template for every page will be:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <jsp:include page="/style/templates/styles.jsp"></jsp:include> <jsp:include page="/style/templates/header.jsp"></jsp:include> <!-- CONTENIDOS --> <jsp:include page="/style/templates/footer.jsp"></jsp:include>
Then we can define all chosen styles in the file /style/templates/styles.jsp:
<!-- Enlaces relativos a hojas de estilo desde un nivel 2 --> <link href="/style/style.css" rel="stylesheet" type="text/css" media="screen" /> <link href="/style/print.css" rel="stylesheet" type="text/css" media="print" />
The header and footer for all the application will be:
/style/templates/header.jsp
/style/templates/footer.jsp
We can see the result in the following screenshot:
I keep the project in this eclipse zip file
This entry was posted on Monday, July 5th, 2010 - 17:04 and is filed under Eclipse, Java, Web. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Have your say
Fields in bold are required. Email addresses are never published or distributed.
Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>URIs must be fully qualified (eg: http://www.domainname.com) and all tags must be properly closed.
Line breaks and paragraphs are automatically converted.
Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.