如何在servlet web模块3.0中指定欢迎文件列表

时间:2015-10-28 12:11:21

标签: java servlets

我正在使用web模块3.0创建servlet,我发现没有创建web.xml,比如我的项目中有多个jsp页面,如何指定欢迎文件,我们是否有任何注释提到欢迎档案?

2 个答案:

答案 0 :(得分:1)

是的,你可以有一个Java文件来提及欢迎文件

/**
 * Returns the cache key for this request.  By default, this is the URL.
 */
public String getCacheKey() {
    return mMethod + ":" + mUrl;
}

/**
 * Supported request methods.
 */
public interface Method {
    int DEPRECATED_GET_OR_POST = -1;
    int GET = 0;
    int POST = 1;
    int PUT = 2;
    int DELETE = 3;
}

或者如果您仍然需要web.xml文件,可以使用以下步骤在Eclipse中手动创建它

  • 右键单击您的网站项目
  • 选择Java EE工具
  • 选择 “生成部署描述符存根”

答案 1 :(得分:1)

您可以结合使用注释@WebServlet和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-list>             
</web-app>

只需手动创建。

相关问题