0

I have two JSPF-Files called header.jspf and footer.jspf

header.jspf:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<link rel="stylesheet" href="resources/css/styles.css">
<title>Onlineshop</title>
</head>
<body>
    <header>
    <hgroup>
    <h1 class="title">Onlineshop</h1>
    </hgroup>
    <nav>
        <a href="index.jsp">Home</a>
        <a href="register.jsp">Registrieren</a>
        <a href="signin.jsp">Einloggen</a>
        <a href="sell.jsp">Verkaufen</a>
        <a href="search.jsp">Suchen</a>
    </nav>
</header>

And my footer.jspf:

    <footer>
        Copyright
    </footer>
</body>
</html>

However, if I want to include them in my other jsp-files, the css file is not working any more. For example I included it like this:

<%@ include file="header.jspf" %>
    <form action ="register" method="post">
    <fieldset>
    <legend>Registrieren</legend>
<table> 
......
</form>
<%@ include file="footer.jspf" %>

In the past, all my header and footer code were inside the jsp-files and it was working fine, however after trying to remove the redundant code by including the jspf-files, the css-file is not applied anymore on the jsp-files.

NoName123
  • 137
  • 5
  • 20
  • You should use the JSP templating system instead of including header/footer's JSP in all your pages, it will be easier : http://stackoverflow.com/questions/1296235/jsp-tricks-to-make-templating-easier – Gaël J Jan 06 '16 at 08:39
  • Thank you for the answer, however I am trying to study JavaEE by reading and doing the examples in a book, so I want to do it step by step in order to understand the whole process. Maybe the JSP templating system will be mentioned later on the book, however right now I would like to understand why the example above is not working. It would be very helpful if someone could explain that. – NoName123 Jan 06 '16 at 09:11
  • Well, is your example JSP at the same level as header ? Have you looked into your browser debugger to see what CSS URL is present in the generated HTML ? – Gaël J Jan 06 '16 at 10:05
  • JSP is compiled on the server into servlet, you can treat it as servlet, and some versions of this servlet doesn't allow you to use some directives. Fortunately there's a lot of other possibilities to do the same like use JSP actions that generally do the same but on another phase of the rendering. – Roman C Jan 06 '16 at 10:17
  • Yeah, I have looked in my browser debugger and the generated HTML code looks fine, it generates: ......However the CSS rules are still not applied. I have also tried: But it doesn't work.... – NoName123 Jan 07 '16 at 20:12
  • Check if you your application server maps .jspf to the jsp servlet. see http://www.coderanch.com/t/171516/java-Web-Component-OCEJWCD/certification/jspf-file-behaving-jsp-file – John Doe May 11 '16 at 12:31

0 Answers0