我想要实现的是类似于 asp.net 中的母版页。我正在学习教程,但我可能错过了一些内容,因为我已将 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...>
。
截屏:
网页.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>
页脚.jspf:
</body>
</html>