如何为 JSF 配置 web.xml、glassfish-web.xml 文件?
How to configure web.xml, glassfish-web.xml files for JSF?
我有一个简单的项目,没有 servlet,但有一个在 JavaServer Faces xhtml 文件中使用的 JavaBean class。
如何配置 web.xml、glassfish-web.xml 文件?整个项目由maven管理。
这里是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>
和 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>
你的问题太宽泛了。您可以向 web.xml
添加很多东西:过滤器、servlet 声明、安全性等等。这取决于你的具体情况。
这是任何 web.xml
都应该包含的非常基本的内容:
<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>
这里有一个 web.xml 的例子,里面有一些东西:
<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 包含很多关于您可以在 web.xml
中拥有什么以及有什么用的信息。我建议你检查一下。
快乐编码:)
终于解决了。看来有两个问题:
- xhtml 文件位于 'src/main/' 文件夹中,而不是 'src/main/webapp/'
- glassfish-web.xml 必须删除。
我有一个简单的项目,没有 servlet,但有一个在 JavaServer Faces xhtml 文件中使用的 JavaBean class。
如何配置 web.xml、glassfish-web.xml 文件?整个项目由maven管理。
这里是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>
和 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>
你的问题太宽泛了。您可以向 web.xml
添加很多东西:过滤器、servlet 声明、安全性等等。这取决于你的具体情况。
这是任何 web.xml
都应该包含的非常基本的内容:
<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>
这里有一个 web.xml 的例子,里面有一些东西:
<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 包含很多关于您可以在 web.xml
中拥有什么以及有什么用的信息。我建议你检查一下。
快乐编码:)
终于解决了。看来有两个问题:
- xhtml 文件位于 'src/main/' 文件夹中,而不是 'src/main/webapp/'
- glassfish-web.xml 必须删除。