The Differences Between JSP & JSPF
By Micah McDunnigan
The difference between a JavaServer Pages (JSP) file and a JavaServer Pages Fragment (JSPF) file is a matter of modularity. JSP files provide the mainstay of the Java code for the JSP framework to translate and run as a webpage, while JSPF files supplement JSP pages with code for specialized functions.
JSP is both the formal name of the JavaServer Pages framework and the extension name for fully functional JavaServer Page source code files. When you put the ".jsp" extension on the end of a source code file, it signifies that the file contains all the necessary syntax for the JSP framework to load its source code and render a page in a Web browser. It does not mean, however, that the file does not reference other files for specialized methods or objects.
A JSPF page is a section of code which the programmer intends to execute within a JSP page. Whereas a JSP file has all the necessary syntax for the JSP framework to process and display it, the JSP framework would not be able to load and execute a JSPF file by itself. Instead, they contain specialized methods and objects which JSP files import and execute.
Programmers commonly reference code in separate source code files in their programs. When you write a function that you will be calling frequently, putting it in its own file and referencing it saves you the time of copying and pasting it directly into all of your projects. Separating a function's code from the source code that is calling it makes your code easier to read, edit and maintain. JSPF files hold the code for such functions, and JSP files call and execute those functions.
You can reference a JSPF file in your JSP source code files by using the syntax "<%@ include file="file-name.jspf" %>" at the top of your file. In this code, "file-name.jspf" is the name of the JSPF file. Before referencing a JSPF page, make sure that you have both uploaded it to your server and that you know the file's directory address. If it is in the same directory as your JSP file then you can just use its file name, but if it is in a different directory, you need to include its full directory address before "file-name.jspf" in your include statement.
Micah McDunnigan has been writing on politics and technology since 2007. He has written technology pieces and political op-eds for a variety of student organizations and blogs. McDunnigan earned a Bachelor of Arts in international relations from the University of California, Davis.