是否可以在不使用jsp:include的情况下将jspf文件添加到jsp页面?

时间:2011-10-01 09:49:54

标签: jsp netbeans header footer jsp-fragments

我想要实现的是类似于asp.net中的母版页。我正在关注tutorial,但我可能错过了一些因为我已将header.jspf和footer.jspf添加到WEB-INF / jspf文件夹而index.jsp在WEB-INF之外。我在web.xml中添加了信息,以便某些jsp页面应该自动添加页眉和页脚。问题可能是index.jsp无法访问WEB-INF文件夹中的任何内容,但我认为我已在本教程的上一步中解决了这个问题。当我运行项目时,我得到的就是删除所有页眉和页脚之后的index.jsp。

我不想使用:<%@include file="header.jspf" %><..jsp:include...>

截图:

Screenshot of the project

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <jsp-config>
        <jsp-property-group>
            <description>header and footer settings</description>
            <url-pattern>/index.jsp</url-pattern>
            <url-pattern>/WEB-INF/view/*</url-pattern>
            <include-prelude>/WEB-INF/jspf/header.jspf</include-prelude>
            <include-coda>/WEB-INF/jspf/footer.jspf</include-coda>
        </jsp-property-group>
    </jsp-config>
</web-app>

header.jspf中:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Webshop</title>
</head>
<body>
     <h1>Webshop</h1>

footer.jspf:

</body>
</html>

1 个答案:

答案 0 :(得分:0)

我也在做那个教程,当我使用Tomcat作为服务器时它不会包含页眉和页脚,我必须使用glassfish服务器,有没有办法让tomcat包括标题和页脚?

编辑:

使用tomcat替换默认标记似乎解决了使用tomcat作为服务器的问题

    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/TR/xmlschema-1/"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">