开发者

where do I place XHTML files to make them visible in GlassFish web container?

This is the structure of my project (exactly these five files):

/p1
  pom.xml
  /src
    /main
      /java
      /webapp
        a.html
        b.xhtml
      /WEB-INF
        faces-config.xml
        web.xml

I'm deploying this WAR to GlassFish and I can successfully access this URL: http://localhost:8080/p1/a.html. When I'm trying to open http://localhost:8080/p1/b.xhtml I'm getting a message

The requested resource (/p1/b.xhtml) is not available.

What am I doing wrong?

ps. My dependencies from pom.xml:

...
<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>${jsf.version}</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-impl</artifactId>
  <version>${jsf.version}</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>com.sun.facelets</groupId>
  <artifactId>jsf-facelets</artifactId>
  <version>${facelets.version}</version>
</dependency>
...

This is my web.xml (core part of it):

<servlet>开发者_运维百科
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

My faces-config.xml:

<application>
  <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>


For the Maven side, things looks ok, except that facelets should also be provided. Actually, I use the following dependency:

<!-- This dependency will bring in everything we need for JAVA EE6 -->
<dependency>
  <groupId>javax</groupId>
  <artifactId>javaee-api</artifactId>
  <version>6.0</version>
  <scope>provided</scope>
</dependency>

For the JSF part, nothing in the server logs? Just in case, could you add the following to your web.xml to see if you get more useful output:

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

As a side note, you don't need your faces-config.xml as Facelets is the default view handler in JSF 2.0. But this shouldn't be a problem.

PS: Personally, I prefer to map the Faces Servlet on something like *.jsf (to clearly de-correlate any mapped url from the actual .xhtml facelet page that will be processed by the Faces Servlet).

See also

  • JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜