Java 如何通过配置web.xml将URL模式从/index.jsp更改为/test/index.jsp?

Java 如何通过配置web.xml将URL模式从/index.jsp更改为/test/index.jsp?,java,xml,jsp,servlets,web.xml,Java,Xml,Jsp,Servlets,Web.xml,我在根文件夹(webcontent)中有一个名为index.jsp的jsp文件,到目前为止,我只是使用以下URL访问页面: 其中Sample是项目名称 现在,我被要求在不更改index.jsp文件位置的情况下将URL模式更改为以下内容(即index.jsp仍位于webcontent文件夹下): 如何通过配置web.xml来实现这一点?这可以通过以下方式实现 <servlet> <servlet-name>BeerAppServlet</servlet

我在根文件夹(webcontent)中有一个名为
index.jsp
的jsp文件,到目前为止,我只是使用以下URL访问页面:

其中Sample是项目名称

现在,我被要求在不更改index.jsp文件位置的情况下将URL模式更改为以下内容(即index.jsp仍位于webcontent文件夹下):


如何通过配置web.xml来实现这一点?

这可以通过以下方式实现

  <servlet>
    <servlet-name>BeerAppServlet</servlet-name>
    <jsp-file>/index.jsp</jsp-file>
  </servlet>
  <servlet-mapping>
    <servlet-name>BeerAppServlet</servlet-name>
    <url-pattern>/test/index.jsp</url-pattern>
  </servlet-mapping>

BeerAppServlet
/index.jsp
BeerAppServlet
/test/index.jsp
中,而不是将其映射到
中,将其映射到