用.jsp或.xhtml或.jsf扩展名创建JSF页面有什么区别 [英] What is the difference between creating JSF pages with .jsp or .xhtml or .jsf extension

查看:98
本文介绍了用.jsp或.xhtml或.jsf扩展名创建JSF页面有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一些示例以.jsp扩展名创建JSF页面,其他示例以.xhtml扩展名创建它们,其他示例选择.jsf. 我只想知道在使用JSF页面时上述扩展之间有什么区别,以及如何选择适当的扩展?

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?

推荐答案

JSP是一种旧的视图技术,已广泛与JSF 1.x结合使用. Facelets(有些人将其泛化为 XHTML )是JSP的继承者,并作为JSF 2.x的默认视图技术引入2009年底.当您看到JSP时,您可能正在阅读针对JSF 1.x的过时书籍,教程或资源.在使用JSF 2.x进行开发时,通常应该忽略它们,而转到针对JSF 2.x的资源,否则您可能会陷入混乱,因为在Facelets上的JSF 2.x中,许多事情都以不同的方式完成.

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.

*.jsf只是web.xmlFacesServlet映射的广泛使用的URL模式之一.其他的是*.faces/faces/*,但是它们来自JSF 1.0/1.1时代.它们都不代表具体的文件扩展名/路径,而仅代表虚拟文件扩展名/路径,仅在URL中指定,例如 http://example.com/contextname/page.jsf .如果您熟悉基本的 Servlets ,那么您应该知道,当请求URL与servlet的URL匹配时,servlet容器将调用servlet.网址格式.因此,当请求URL匹配*.jsf时,将以这种方式调用FacesServlet.使用JSP时,它将实际上执行page.jsp.使用Facelets时,实际上会编译page.xhtml.

The *.jsf is just one of widely used URL patterns of the FacesServlet mapping in web.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 the FacesServlet will be invoked this way. When using JSPs, it would actually execute page.jsp. When using Facelets, this would actually compile page.xhtml.

自JSF 2.x起,您还可以将*.xhtml用作URL模式.这样,您无需在指定URL时感到困惑.在带有Facelets 1.x的JSF 1.x中不可能将*.xhtml用作URL模式,因为FacesServlet随后将在无限循环中运行,每次都会调用它自己.使用*.xhtml的另一个优点是,只要最终用户有意将浏览器地址栏中的URL扩展名从例如.jsf更改为.xhtml,最终用户就无法看到原始的JSF源代码.不能将*.jsp用作URL模式,因为这样,已经使用该URL模式的容器的内置JspServlet将会被覆盖,然后FacesServlet将不再能够以JSP为基础

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 the FacesServlet 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 builtin JspServlet, which is already using that URL pattern, would be overridden and then the FacesServlet wouldn't be able to feed on JSPs anymore.

  • What is the difference between JSF, Servlet and JSP?
  • Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?
  • JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?

这篇关于用.jsp或.xhtml或.jsf扩展名创建JSF页面有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆