What is .jspf file extension? How to compile it?

JavaJspJsp Fragments

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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:

<%@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.

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 first step; 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.

Solution 2 - Java

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.

Solution 3 - Java

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.

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.

Source : Ibm Infocentre

Solution 4 - Java

IBM says that .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.

They're mentioned in Sun's developer resources in the same context - a naming convention for JSP Fragments.

Solution 5 - Java

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.

Other languages and frameworks have their own term for the equivalent concept. In Ruby on Rails, for example, they're called partials.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongiriView Question on Stackoverflow
Solution 1 - JavakdgregoryView Answer on Stackoverflow
Solution 2 - JavakodepetView Answer on Stackoverflow
Solution 3 - JavavmishraView Answer on Stackoverflow
Solution 4 - JavabrabsterView Answer on Stackoverflow
Solution 5 - JavaJohn FeminellaView Answer on Stackoverflow