views:

57

answers:

1

Hi,

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 would do it?

+1  A: 

Don't map the FacesServlet on all requests. You don't want to get JS/CSS/image/whatever-static 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).

BalusC
Hi,that was also the option I thought about (mapping only .xhtml). I use Eclipse Helios and it generates .xhtml files as default and also the above web.xml with the servletmapping of /faces/..I thought .jsf is not recommend anymore in JSF 2.0 ? I only have dynamic pages (because of i18n) so mapping every .xhtml should be ok
Tim
Ah, that must be then my specific Eclipse configuration. The only which is not recommended anymore in JSF 2.0 is using JSP instead of Facelets :)
BalusC