Website in JSP with header with param, footer and index part.

It is another my post. Today we ceate very simple JSP project in Netbeans.

So open Netbeans IDE and from menu choose File->New Project.


In New Project window from Categories select Java Web and from Projects choose Web Application.

x2Click Next button. In Project Name field write MyFirstJSP and click the Next button.

x3From Server list select your favorite server. I chose tomcat7. Click the Next button.

x4In another window you may click the Finish button.

x5In tree of project you see index.jsp file.

x6Now we may create two another files: footer.jsp and header.jsp. So right click on project node and choose New->JSP.

x7In New JSP window in File Name write header and click the Finish button.

x8In the same way create footer.jsp file.

x9You have tree jsp files: header, footer and index. Paste into header.jsp this code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" media="screen"  href="css/main.css">
        <title><%= request.getParameter("title") %></title>

x14You see stylesheet file include into website. Create css file. Right click the Web Pages node and choose New->Folder.

x15In New Folder window write in File Name field css and click the Finish button.

x16Right click the css folder and choose New->Other.

x17From New File window form Categories choose Other and from File Types select Cascading Style Sheet. Click the Next button.

x18In File Name field write main and click the Finish button.



In the footer.jsp file paste this code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

x22And in index.jsp paste the code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<jsp:include page="header.jsp">
<jsp:param name="title" value="My website"/>

        <h1>It is my first website in JSP.</h1>
<jsp:include page="footer.jsp" /> 


All files contain page directive with contentType attribute and pageEncoding attribute.  In index.jsp file adding header and footer file is by means of include directive with page attribute. If you would like to add param to this part website you must add in include tags (with page attribute)  param tag with name of param and its value. In this example we add title of website into it.

Run your application.