开发者

Preferred way to set up a JSF start page?

I'm using JSF 2.0 to build a website. Eclipse generated the following web.xml file

...
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
...

So to view my application i have to visit "localhost/myApp/faces/index.xhtml". I would prefer to view it directly by visiting "localhost/myApp/index.xhtml"

I see two options for this:

Changing the web.xml to the following

...
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
...

Or setting up an index.xhtml in my base dir that does a javascript/meta direct to faces/index.xhtml.

Which do you think is better ? Or is there another way how you w开发者_JAVA技巧ould do it?


Don't map the FacesServlet on all requests. You don't want to get static (non-JSF) requests go through the whole JSF lifecycle. It'll only add unnecessary overhead. Rather map the FacesServlet on an url-pattern of *.xhtml.

If you have another xhtml files as well which doesn't need to go through the JSF factory, then rather choose a different url-pattern, like the commonly used *.jsf. You don't need to rename the actual file extension, the FacesServlet will automagically locate the right resource.

Definitely do not use a JS/meta redirect for the home page. Just declare it as <welcome-file> in web.xml.


That said, when having the latest version and properly configured, Eclipse should by default autogenerate the web.xml with the FacesServlet mapped on an url-pattern of *.jsf. Ensure that you're using the latest version (Helios) and doing everything right in Eclipse (configure project facets).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜