JSP---web.xml中设置前后台不同的头部和底部

目录结构

header.jspf 

<%@ page pageEncoding="utf-8" %>
<html>
<head></head>
<body>
<h1 style="background:#999;color:#fff;padding:10px;">hello website.</h1>

admin_header.jspf

<%@ page pageEncoding="utf-8" %>
<html>
<head></head>
<body>
<h1 style="background:#999;color:#fff;padding:10px;">hello admin information management system.</h1>

footer.jspf

<%@ page import="java.util.Calendar"  pageEncoding="utf-8" %>
<h1 style="background:#999;color:#fff;padding:10px;">&copy;2000-<%= Calendar.getInstance().get(Calendar.YEAR) %>  beast-king corp.</h1>

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">
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <jsp-config>
        <jsp-property-group>
            <url-pattern>/main/*</url-pattern>
            <page-encoding>UTF-8</page-encoding>
            <default-content-type>text/html</default-content-type>
            <include-prelude>/jspf/header.jspf</include-prelude>
            <include-coda>/jspf/footer.jspf</include-coda>
        </jsp-property-group>
        
        <jsp-property-group>
            <url-pattern>/admin/*</url-pattern>
            <page-encoding>UTF-8</page-encoding>
            <default-content-type>text/html</default-content-type>
            <include-prelude>/jspf/admin_header.jspf</include-prelude>
            <include-coda>/jspf/footer.jspf</include-coda>
        </jsp-property-group>
    </jsp-config>
</web-app>
原文地址:https://www.cnblogs.com/beast-king/p/5537332.html