Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java web.xml URL模式_Java_Html_Servlets_Web.xml_Url Pattern - Fatal编程技术网

Java web.xml URL模式

Java web.xml URL模式,java,html,servlets,web.xml,url-pattern,Java,Html,Servlets,Web.xml,Url Pattern,有人能告诉我关于设置URL模式的规则的信息吗?如果我使用/作为索引页,我还需要使用request.getRequestDispatcher/html/file.html.forwardrequest,response File File.html位于war文件夹下的html文件夹中,html文件夹位于WEB-INF的同一文件夹中 谁能给我提个建议吗? 谢谢您可以在web.xml中定义一个servlet,如下所示,然后使用request.getRequestDispatcherfile.forwa

有人能告诉我关于设置URL模式的规则的信息吗?如果我使用/作为索引页,我还需要使用request.getRequestDispatcher/html/file.html.forwardrequest,response

File File.html位于war文件夹下的html文件夹中,html文件夹位于WEB-INF的同一文件夹中

谁能给我提个建议吗?
谢谢

您可以在web.xml中定义一个servlet,如下所示,然后使用request.getRequestDispatcherfile.forwardrequest,response,本质上,您将请求发送到一个servlet,其映射为/file,该servlet将指向您的资源/html/file.html。请注意,尽管元素名是jsp文件,但您可以从中指向HTML

<servlet>
    <servlet-name>FileServlet</servlet-name>
    <jsp-file>/html/file.html</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/file</url-pattern>
</servlet-mapping>
二,。扩展映射:

如果要创建扩展映射,请使用servlet映射*。。例如:

<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>*.html</url-pattern> <!-- http://localhost:7001/MyTestingApp/index.html would map this servlet. Also, please note that this servlet mapping would also be selected even if the request is `http://localhost:7001/MyTestingApp/foo/index.html` unless you have another servlet mapping as `/foo/*`.  -->
</servlet-mapping>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/</url-pattern> <!-- Suppose you have mapping defined as in above 2 example as well, and request comes for `http://localhost:7001/MyTestingApp/catalog/index.jsp` then it would mapped with servlet  -->
</servlet-mapping>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/catalog</url-pattern> <!-- Only requests with http://localhost:7001/MyTestingApp/catalog will match this servlet   -->
</servlet-mapping>
四,。精确匹配映射:

假设要定义精确匹配映射,则不要使用任何通配符或其他字符,并定义精确匹配,如/catalog。例如:

<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>*.html</url-pattern> <!-- http://localhost:7001/MyTestingApp/index.html would map this servlet. Also, please note that this servlet mapping would also be selected even if the request is `http://localhost:7001/MyTestingApp/foo/index.html` unless you have another servlet mapping as `/foo/*`.  -->
</servlet-mapping>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/</url-pattern> <!-- Suppose you have mapping defined as in above 2 example as well, and request comes for `http://localhost:7001/MyTestingApp/catalog/index.jsp` then it would mapped with servlet  -->
</servlet-mapping>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/catalog</url-pattern> <!-- Only requests with http://localhost:7001/MyTestingApp/catalog will match this servlet   -->
</servlet-mapping>
六,。匹配所有映射:

如果希望将所有请求与一个映射匹配,或者覆盖所有其他servlet映射,那么创建一个映射为/*

以下是JMS规范的汇总图:


您可以在web.xml中定义一个servlet,如下所示,然后使用request.getRequestDispatcherfile.forwardrequest,response,本质上,您将请求发送到一个servlet,该servlet的映射为/file,该servlet将指向您的资源/html/file.html。请注意,尽管元素名是jsp文件,但您可以从中指向HTML

<servlet>
    <servlet-name>FileServlet</servlet-name>
    <jsp-file>/html/file.html</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/file</url-pattern>
</servlet-mapping>
二,。扩展映射:

如果要创建扩展映射,请使用servlet映射*。。例如:

<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>*.html</url-pattern> <!-- http://localhost:7001/MyTestingApp/index.html would map this servlet. Also, please note that this servlet mapping would also be selected even if the request is `http://localhost:7001/MyTestingApp/foo/index.html` unless you have another servlet mapping as `/foo/*`.  -->
</servlet-mapping>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/</url-pattern> <!-- Suppose you have mapping defined as in above 2 example as well, and request comes for `http://localhost:7001/MyTestingApp/catalog/index.jsp` then it would mapped with servlet  -->
</servlet-mapping>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/catalog</url-pattern> <!-- Only requests with http://localhost:7001/MyTestingApp/catalog will match this servlet   -->
</servlet-mapping>
四,。精确匹配映射:

假设要定义精确匹配映射,则不要使用任何通配符或其他字符,并定义精确匹配,如/catalog。例如:

<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>*.html</url-pattern> <!-- http://localhost:7001/MyTestingApp/index.html would map this servlet. Also, please note that this servlet mapping would also be selected even if the request is `http://localhost:7001/MyTestingApp/foo/index.html` unless you have another servlet mapping as `/foo/*`.  -->
</servlet-mapping>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/</url-pattern> <!-- Suppose you have mapping defined as in above 2 example as well, and request comes for `http://localhost:7001/MyTestingApp/catalog/index.jsp` then it would mapped with servlet  -->
</servlet-mapping>
<servlet-mapping>
    <servlet-name>FileServlet</servlet-name>
    <url-pattern>/catalog</url-pattern> <!-- Only requests with http://localhost:7001/MyTestingApp/catalog will match this servlet   -->
</servlet-mapping>
六,。匹配所有映射:

如果希望将所有请求与一个映射匹配,或者覆盖所有其他servlet映射,那么创建一个映射为/*

以下是JMS规范的汇总图:


你需要抓起一份并阅读它。特别是第10章和第12章。你需要抓起一本,读一读。特别是第10章和第12章。