java - 如何为JSF配置web.xml、glassfish-web.xml文件?

标签 java maven jsf jakarta-ee glassfish

我有一个简单的项目,没有 servlet,但有一个在 JavaServer Faces xhtml 文件中使用的 JavaBean 类。

enter image description here

如何配置 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/

相关文章:

java - 为什么使用 maven shade 插件重定位不起作用?

java - 直接从 JSF/richfaces 访问基于 java 的 DOM 树

java - 为什么 Java 不附带 CopyOnWriteMap?

java - TextSwitcher 重力底部中的 TextView 无法工作

java - 如何将滚动 Pane 内容保存为 jpg 文件

javascript - 重定向前调用JS函数

jsf - Facelets dataTable 遍历所有对象的属性

java - GWT 和 web.xml

java - 是否有任何理由在 Maven 中为我自己的传递依赖项保留显式依赖声明?

java - Gradle Java项目布局?