【发布时间】:2011-08-05 20:24:13
【问题描述】:
首先,我来自 PHP 背景(这个问题可能很明显)。这是一个用 PHP 完成的简单任务,但我对如何用 jsp 完成这个任务感到非常困惑。
这是我在服务器上的文件夹结构:
/home +
|
+-/user-+
|
+-/includes+
| |
| +/footer.jsp
|
+-/public_html+
|
+/index.jsp
public_html 是 Apache Tomcat 服务的目录。因此,如果有人浏览我的域 (sampledomain.com),他们会看到 index.jsp
我不希望通过网络直接访问“footer.jsp”。因此,它位于位于“index.jsp”上方一个目录的包含目录中。没有可能的 URL 可以在浏览器中键入以直接访问 footer.jsp。
这是footer.jsp的内容
<div id="footer">
<p>This is a footer</p>
</div>
这里是index.jsp的内容
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Hello World</h1>
<%@ include file="../includes/footer.jsp" %>
</body>
</html>
我收到一个 tomcat 错误,提示找不到文件“/../includes.footer.jsp”。如何包含网页的 public_html 目录之外的文件。
在 php 中,我只是这样做
<?php include("../includes/footer.php") ?>
【问题讨论】: