I saw some examples creating the JSF pages with .jsp
extension, other examples creating them with .xhtml
extension, and other examples choose .jsf
.
I just would like to know what the difference is between above extensions when working with JSF pages, and how to choose the appropriate extension?
相关问题
- java.lang.NullPointerException at java.io.PrintWri
- h:selectOneMenu in p:dataTable doesn't submit
- PrimeFaces block UI does not work when the compone
- primefaces orderlist not getting updated with the
- JSF2 composite cc.attrs expression does not evalua
相关文章
- jsp里面的画布功能,为什么会出错?求大佬找下问题
- JSP String formatting Truncate
- Forward request from servlet to jsp
- Comparing string and boolean in Expression languag
- How to allow numbers only using f:validateRegex
- JSF 2.0: ajax request when press ENTER
- Passing a Java object value in Custom JSP tag
- Passing a enum value as a tag attribute in JSP
.jsp
files are generally used for JSF views defined using JavaServer Pages..xhtml
files are generally used for JSF views defined using Facelets.This can be changed via configuration (e.g. see the
javax.faces.DEFAULT_SUFFIX
andjavax.faces.FACELETS_SUFFIX
configuration parameters.)Other extension mappings (
*.jsf
,*.faces
) tend to be used for processing requests via theFacesServlet
. This is a logical mapping to the view which the JSF runtime will handle. How mappings are handled is defined in theweb.xml
(that doesn't have to be done using extensions; the/faces/*
mapping is often used.From the spec:
JSP is an old view technology and widely used in combination with JSF 1.x. Facelets (by some people overgeneralized as XHTML) is the successor of JSP and introduced as default view technology of JSF 2.x at end of 2009. When you were seeing JSPs, you were perhaps reading outdated books, tutorials or resources targeted on JSF 1.x. You should generally ignore them when developing with JSF 2.x and head to resources targeted on JSF 2.x, otherwise you may end up in confusion because many things are done differently in JSF 2.x on Facelets.
The
*.jsf
is just one of widely used URL patterns of theFacesServlet
mapping inweb.xml
. Other ones are*.faces
and/faces/*
, but those are from back in the JSF 1.0/1.1 ages. They all do not represent the concrete file extension/path, but just a virtual file extension/path and is to be specified in URLs only like so http://example.com/contextname/page.jsf. If you are familiar with basic Servlets, then you should know that the servletcontainer will invoke the servlet when the request URL matches the servlet's URL pattern. So when the request URL matches*.jsf
, then theFacesServlet
will be invoked this way. When using JSPs, it would actually executepage.jsp
. When using Facelets, this would actually compilepage.xhtml
.Since JSF 2.x you can also use
*.xhtml
as URL pattern. This way you don't need to get confused when specifying URLs. Using*.xhtml
as URL pattern was not possible in JSF 1.x with Facelets 1.x, because theFacesServlet
would then run in an infinite loop calling itself everytime. An additional advantage of using*.xhtml
is that the enduser won't be able to see raw JSF source code whenever the enduser purposefully changes the URL extension in browser address bar from for example.jsf
to.xhtml
. It is not possible to use*.jsp
as URL pattern, because this way the container's builtinJspServlet
, which is already using that URL pattern, would be overridden and then theFacesServlet
wouldn't be able to feed on JSPs anymore.See also: