Is it possible to add jspf files to a jsp page without using jsp:include?

大憨熊 提交于 2019-12-01 19:58:04

问题


What I want to achieve is something similar to a master page in asp.net. I'm following a tutorial, but I may have missed something cause I have added my header.jspf and footer.jspf to the WEB-INF/jspf folder and index.jsp is outside of WEB-INF. I have added info in web.xml so that certain jsp-pages should automatically add the header and footer. The problem might be that index.jsp can't access anything inside the WEB-INF folder, but I thought I had solved that in a previous step in the tutorial. When I run the project, all I get is what's left of index.jsp after I remove all the header and footer stuff.

I don't want to use: <%@include file="header.jspf" %> and <..jsp:include...>.

Screenshot:

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:


I'm also doing that tutorial, and when I use Tomcat as the server it won't include the header and the footer, I have to use the glassfish server, is there any way to make tomcat include the header and the footer?

EDIT:

Replacing the default tag with this one seems to have solved the problem using tomcat as the server

    <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">


来源:https://stackoverflow.com/questions/7619480/is-it-possible-to-add-jspf-files-to-a-jsp-page-without-using-jspinclude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!