繁体   English   中英

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

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

我有一个简单的项目,没有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>

本文档包含有关在web.xml可以包含的内容以及用途的大量信息。 我建议你检查一下。

快乐编码:)

我终于解决了。 看来有两个问题:

  • xhtml文件位于“ src / main /”文件夹中,而不是“ src / main / webapp /”中
  • glassfish-web.xml必须删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM