When to Use JSP Vs. JSPF

Save

JSP or Java Server Pages are the Java-language equivalent of Microsoft's Active Server Pages and PHP Web applications. JSP files combine Java and HTML code that is compiled and run as Java servlets. The term “JSPF” refers to Java Server Page fragment files, which are not complete JSP pages and cannot be compiled without errors. A JSP file can include one or more child JSP or JSPF files into a single file that is compiled and run as a single servlet.

Reusing JSP Code

  • JSPF files can be used to make programming a complex Java Web application less tedious and error-prone by splitting the application into several smaller, more manageable units or modules. Ideally, each module should address a single part of the complete program and be general in nature so that the code can be reused in future JSP applications. The parent JSP file will have an "include" directive for each JSPF fragment file, which assembles them all into a complete JSP application.

Refactoring Code

  • Breaking a large JSP file into smaller, more modular JSPF fragments has the additional advantage of making the task of code refactoring easier. Code refactoring is a technique for improving the quality of code by examining it, dividing it into logical units, and then rewriting each of these units one by one. Using JSPF fragments can help eliminate bugs and increase the performance of each unit and the final reassembled application.

Access Restriction

  • By convention, JSPF fragments should be saved in the "/WEB-INF/jspf/" directory. This directory is accessible by servlet containers such as Tomcat and JBoss Application Server, but not by Web servers like Apache or Microsoft IIS. You can split a complete JSP page into JSPF fragment files and hide them in the "/WEB-INF/jspf/" directory. You can also hide a complete JSP page from Web access by storing it with the JSPF fragments.

JSP Interactions

  • Complete JSP pages can import other complete JSP pages as well as JSPF fragments. This is done using the "dsp:include" or "jsp:include" directives. The "dsp:include" directive will allow a parent JSP file to pass parameters to methods in the child JSP files. The "jsp:include" directive does not allow parameter passing to methods in JSPF files but does allow JSPF fragment methods to access global data and other objects to which Java scope rules permit access.

References

  • Photo Credit Stockbyte/Retrofile/Getty Images
Promoted By Zergnet

Comments

Resources

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!