This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Whats the difference between JSP and JSPF, I understand JSPF is JSP Fragment. WHat exactly is meant by that ? How can I craete a JSP fragment ? What is the difference between them from coding point of view ? What do I need to include or exclude from JSp in order to create a JSPF ?
Is there any diference in coding of JSP and JSPF ? If I want to give JSPF extension to a JSP page, will that work ? or do I need to code JSP page in a certain way in order to call it JSPF ? If there is no difference in coding, then why need JSPF ? We can just create JSP page and include it in another JSP page with include action (oe whatever legal way). What difference does it make , if you are using JSP or JSPF if there is no difference in coding or of other kind ?
nirjari patel wrote:Is there any diference in coding of JSP and JSPF ?
A jspf doesn't need to be a complete and sytnax-complete JSP, as it is statically included in a JSP (that does need to be complete).
If I want to give JSPF extension to a JSP page, will that work ?
Of course not. Why would you do such a thing?
do I need to code JSP page in a certain way in order to call it JSPF ?
The JSP simply uses the include directive to include the fragment.
We can just create JSP page and include it in another JSP page with include action (oe whatever legal way).
Yes, you can do that. But in the case of the include action, the included JSP must be syntax-complete.
Joined: Apr 23, 2009
Thanks. Things are lot clearer now. I tried to google for this info, but nowhere any useful info is provided about JSPF. Any idea which website or book explains these things in detail and with sample code ?
Can you please provide a sample code of JSPF in here ?
There's no book or article that I am aware of. That's because it's just a simple concept which you apparently missed from my example: a fragment file can contain anything that can be statically included in a JSP.
Joined: Apr 23, 2009
Can I view a JSPF page in the web link , the way I can view a JSP page ? Or do I need to call a JSPF pafe within a JSP page and then only I can view it ?
By that I mean , can a JSPF be used independently on its own ?
I am working on Interwoven CMS in which we have two programs. One is outputting JSP page and other code is outputting JSPF page. Now when I click on JSP page, I can seethe final output, how it will look in webpage. Nut when I click om JSPF, I get an error "Oops! This link appears to be broken.".
So now I am thinking, is it allowed to use JSPF without embedding or calling it in JSP page ?
It should be noted that the JSPF extension is more of a convention/best practice rather than officially specified.
Kind of like struts uses the ".do" extension, and we use 'i' for a loop variable.
The JSPF extension is an indication to the programmer that
"This file is a fragment of a JSP and will only be used via <%@ include %> in other JSPs"
There is nothing mandatory about this. You don't have to use the JSPF extension. You can include any file you like with the <%@ include %> directive.
It is merely a defacto standard that has emerged of "this is the way we do things around here".
Also consider if you should use a tag file instead. Since you can have a tag file implemented in JSP language, the include feels more natural. I've been using tag files for reusable code and haven't used a jspf since tag files allowed HTML/JSP (rather than having to be implemented in Java.)