hal
hal

Reputation: 841

How to configure web.xml, glassfish-web.xml files for JSF?

I have simple project with no servlet but with a JavaBean class used in JavaServer Faces xhtml files.

enter image description here

How do i configure web.xml, glassfish-web.xml files? The whole project is managed by maven.

Here is the content of web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    version="4.0">

    <display-name>LoginJSFApp</display-name>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

and glassfish-web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <context-root>/LoginJSFApp</context-root>
</glassfish-web-app>

Upvotes: 0

Views: 4900

Answers (2)

hal
hal

Reputation: 841

I have finally solved it. It appears that there were two problems:

  • xhtml files were in 'src/main/' folder instead of 'src/main/webapp/'
  • glassfish-web.xml had to be removed.

Upvotes: 1

ikos23
ikos23

Reputation: 5354

Your question is too broad. There are a lot of things you can add to web.xml : filters, servlet declarations, security stuff and many more. It depends on you each concrete case.

This is a very basic stuff that any web.xml should contain:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    // stuff here

</web-app>

Here is an example of web.xml with some stuff inside:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <display-name>HelloWorld Application</display-name>
    <description>
        This is a simple web application.
    </description>

    <!-- This is how you can add servlet -->
    <servlet>
        <servlet-name>HelloServlet</servlet-name>
        <servlet-class>examples.Hello</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloServlet</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>

</web-app>

This documentation contains a lot of information about what you can have inside web.xml and what for. I would suggest you check it.

Happy Coding :)

Upvotes: 3

Related Questions