How does the server and/or browser handle JSP and JSPF files differently?

680 Views Asked by At

Edit: This question was asked in response to incorrect observations I made. Please disregard.

I know that JSPFs are used to define fragments that can be included inside JSPs.

Beyond this convention, are there differences in how the server (eg Tomcat) or the user-agent (eg firefox, google bot, etc) might treat a file?

Our website has a few popups / dialog boxes that are loaded via AJAX. The content for most of these are stored inside JSPFs, and referenced in the url (eg, http://www.domain.com/folder/file.jspf). Recently we found that if the popup was inside a JSP instead, it would behave differently in the following ways:

1) Google would index it as a standalone page.
2) jQuery's $(document).ready(function() {alert('this code is executed')}); never runs.

2

There are 2 best solutions below

1
Alex Karasev On

First of all, the browser handles neither JSP nor JSPF files directly.

Instead, the browser requests a resource by URL and the server (in your case, Tomcat) responds with a document in HTML format.

Yes, you asked for a .jsp resource, but the server compiled the page and Tomcat produced HTML output to the browser.

At that moment, the browser handled a plain HTML page.

I do see a potential problem with directly-accessing a JSPF file via a URL. Fragments should be included by a special JSP directive: include. See Use of Composite View Patterns in Code conventions

0
Fabri Pautasso On

The only way to allow to construct a URL to arrive to a jspf file is putting them in the same directory as normal JSP files. (This is not allowed if you put them inside /WEB-INF/) So, when you do that, will depend on the container you are using. Tomcat will retrieve the page as a text document. A front-end web-server, however, can block these URLS. What is .jspf file extension? How to compile it?

Hope it helps.