JSP 规范中的相对 URL

发布于 2024-10-22 19:18:03 字数 684 浏览 2 评论 0原文

我从 JSP 2.1 规范文档中摘取了以下段落。我很困惑,我需要一些帮助。

页面相对路径是不以斜杠 (/) 开头的路径。它被解释为相对于当前的JSP页面,或者当前的JSP文件或标记文件, 取决于路径的使用位置。

到这为止我都很好。然后,

对于在文件属性中使用路径的 include 指令(请参阅第 JSP.1.10.3 节),解释是相对于 JSP 文件或标记文件的。对于 jsp:include 操作(参见第 JSP.5.4 节,),其中路径在页面属性中使用, 解释是相对于JSP页面的。在这两种情况下,当前页面或 文件由以 / 开头的某个路径表示,然后由新文件修改 规范生成以 / 开头的路径。

上面的段落说,在这两种情况下解释都是相对于 JSP 页面的,但它为什么会以 '/' 开头?根据第一段页面相对路径不以斜杠开头,对吗?是打字错误吗?并且 shd 它就像'在这两种情况下路径都应该像“../myfile.jsp”?

新路径通过 ServletContext 对象进行解释。有关此解释的确切详细信息,请参阅第 JSP.1.10.5 节。

如果路径以斜线开头,我同意这一点。

I have taken below paragraphs from JSP 2.1 specification document. I'm confused and I need some help with this.

A page relative path is a path that does not start with a slash (/). It is to be interpreted as relative to the current JSP page, or the current JSP file or tag file,
depending on where the path is being used.

I'm good till this. Then,

For an include directive (see Section JSP.1.10.3) where the path is used in a file attribute, the interpretation is relative to the JSP file or tag file. For a jsp:include action (see Section JSP.5.4, “<jsp:include>”) where the path is used in a page attribute,
the interpretation is relative to the JSP page. In both cases the current page or
file is denoted by some path starting with / that is then modified by the new
specification to produce a path starting with /.

The above paragraph says that, in both the cases interpretation is relative to JSP page but how come it will start with '/' ? As per the first paragraph page relative paths does not start with slash right ? Is it a typing mistake ? and shd it be like 'in both cases path should be like "../myfile.jsp" ??

The new path is interpreted through the ServletContext object. See Section JSP.1.10.5 for exact details on this interpretation.

I agree to this point if the path starts with a slash.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里泪两行 2024-10-29 19:18:03

规范规定“当前页”的值将以“/”开头。这是路径相对于的页面,而不是相对路径本身。

因此,如果您指定相对路径,它将使用当前路径(始终以“/”开头)来计算新路径。生成的新路径也将以“/”开头的路径。

您只需使用相对路径来描述相对于当前路径的新路径。

The specification is saying the value of "Current Page" will start with '/'. That is the page that the path is relative to, not the relative path itself.

So if you specify a relative path, it will use the current path, which will always start with '/', to calculate the new path. The resulting new path will also be a path starting with '/'.

You just use a relative path to describe a new path in terms relative to the current path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文