我有一个简单的项目,没有 servlet,但有一个在 JavaServer Faces xhtml 文件中使用的 JavaBean 类。
如何配置 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
中可以包含哪些内容以及用途的信息。我建议你检查一下。
快乐编码:)
关于java - 如何为JSF配置web.xml、glassfish-web.xml文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49697229/