Java .jspf 文件扩展名是什么?如何编译它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2081005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is .jspf file extension? How to compile it?
提问by giri
What are .jspf files in JSP? As I know the compiler will look for .jsp files to compile, then how are the .jspf files compiled?
JSP 中的 .jspf 文件是什么?据我所知,编译器会寻找要编译的 .jsp 文件,那么 .jspf 文件是如何编译的?
采纳答案by kdgregory
As others have noted, .jspf files are JSP fragments. They're designed to be statically included in another JSP file, not compiled on their own:
正如其他人所指出的,.jspf 文件是 JSP 片段。它们被设计为静态包含在另一个 JSP 文件中,而不是自己编译:
<%@include file="/WEB-INF/jspf/example.jspf" %>
You'll note that this example comes from the /WEB-INF/jspf
directory. This means that it is not accessible outside of the web application; there's no way to construct a URL that can retrieve it. If you put them in the same directory as "normal" JSP files, you can construct such a URL; Tomcat, for example will retrieve the page as a text document. A front-end web-server, however, can block these URLS.
你会注意到这个例子来自/WEB-INF/jspf
目录。这意味着它不能在 Web 应用程序之外访问;没有办法构建一个可以检索它的 URL。如果将它们与“普通”JSP 文件放在同一目录中,则可以构造这样的 URL;例如,Tomcat 会将页面作为文本文档进行检索。但是,前端 Web 服务器可以阻止这些 URL。
I like JSPF files as a first step in refactoring large JSP pages. Since they're statically included, you can extract a small chunk of the file without making provision for scriptets or variables, leading to pages that are somewhat more maintainable (and I want to stress, it's a firststep; dynamic includes and taglibs are usually a better long-term solution). When refactoring, I believe in keeping the fragments close to their parent files; this is when having a web-server to block URLs becomes useful.
我喜欢将 JSPF 文件作为重构大型 JSP 页面的第一步。因为他们是静态包含,你可以提取该文件的一小块没有作出规定scriptets或变量,导致那是有点更容易维护的页面(我想强调,这是一个第一步骤,动态包括和标记库通常是更好的长期解决方案)。重构时,我相信让片段靠近它们的父文件;这就是使用 Web 服务器来阻止 URL 变得有用的时候。
回答by brabster
IBM saysthat .jspf is for JSP fragments. A fragment may not be complete and compilable source, so they likely can't be compiled independently of another, complete, source that references them.
IBM 说.jspf 用于 JSP 片段。片段可能不是完整和可编译的源代码,因此它们可能无法独立于引用它们的另一个完整源代码进行编译。
They're mentioned in Sun's developer resourcesin the same context - a naming convention for JSP Fragments.
在Sun 的开发人员资源中,它们在同一上下文中被提及- JSP 片段的命名约定。
回答by John Feminella
In many web frameworks, it's possible to assemble views and pages from smaller, shared views and pages. Using JSP, these smaller pieces are called fragments. As the name implies, they're not necessarily a complete representation without some larger context.
在许多 Web 框架中,可以从较小的共享视图和页面组合视图和页面。使用 JSP,这些较小的部分称为片段。顾名思义,它们不一定是没有更大上下文的完整表示。
Other languages and frameworks have their own term for the equivalent concept. In Ruby on Rails, for example, they're called partials.
其他语言和框架对等价概念有自己的术语。例如,在 Ruby on Rails 中,它们被称为partials。
回答by kodepet
JSP Fragments can be compared to server side includes. These fragments are not compiled on their own, however there are compiled along side the page in which its included. If I've to display different pages base on a user preference, i will opt for jspf.
JSP 片段可以与服务器端包含进行比较。这些片段不是自己编译的,而是在包含它的页面旁边编译的。如果我必须根据用户偏好显示不同的页面,我会选择 jspf。
回答by vmishra
What :.jspf files are generally files that are included in .jsp files via the include directive. The 'f' stands for 'fragment' as these files are not full JSPs in and of themselves.
内容:.jspf 文件通常是通过 include 指令包含在 .jsp 文件中的文件。“f”代表“片段”,因为这些文件本身并不是完整的 JSP。
How to Compile:Since .jspf is a fragment of a jsp hence it may not be complete and compilable source, so most of the time it can't be compiled independently of another, complete, source that references them.
如何编译:由于 .jspf 是 jsp 的一个片段,因此它可能不是完整和可编译的源代码,所以大多数时候它不能独立于引用它们的另一个完整源代码进行编译。
Source: Ibm Infocentre
来源:IBM 信息中心