是否可以在不使用 jsp:include 的情况下将 jspf 文件添加到 jsp 页面?
我想要实现的是类似于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...>
。
屏幕截图:
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也在做那个教程,当我使用Tomcat作为服务器时,它不会包含页眉和页脚,我必须使用glassfish服务器,有什么办法让tomcat包含页眉和页脚吗?
编辑:
用这个标签替换默认标签似乎已经解决了使用 tomcat 作为服务器的问题
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