WebDAV是一種超文本傳輸協議,Tomcat默認是支持WebDAV的,且默認為禁用狀態。
更多詳細信息,請參考:
https://zh.wikipedia.org/wiki/WebDAV
http://www.webdav.org/
開啟步驟如下:
1、在Tomcat的webapps目錄下新建webdav文件夾,并在此文件夾下新建WEB-INF\web.xml文件
完整的文件目錄為:C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\webdav\WEB-INF\web.xml
配置Servlet,添加如下節點:
<servlet><servlet-name>webdav</servlet-name><servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class><init-param><param-name>debug</param-name><param-value>0</param-value></init-param><init-param><param-name>listings</param-name><param-value>true</param-value></init-param><!-- Read-Write Access Settings --><init-param><param-name>readonly</param-name><param-value>false</param-value></init-param></servlet><!-- URL Mapping --><servlet-mapping><servlet-name>webdav</servlet-name><url-pattern>/*</url-pattern></servlet-mapping>
配置權限,添加如下節點:
<security-constraint><web-resource-collection><web-resource-name>webdav</web-resource-name><!-- Detect WebDAV Methods in URL For Whole Application --><url-pattern>/*</url-pattern><http-method>PROPFIND</http-method><http-method>PROPPATCH</http-method><http-method>COPY</http-method><http-method>MOVE</http-method><http-method>LOCK</http-method><http-method>UNLOCK</http-method></web-resource-collection><!-- Restrict access by role --><auth-constraint><role-name>*</role-name></auth-constraint></security-constraint><login-config><auth-method>BASIC</auth-method><realm-name>webdav</realm-name></login-config><security-role><description>WebDAV User</description><role-name>webdav</role-name></security-role>
提示:<role-name>為自定義權限名稱。
根據上面權限名稱,在Tomcat賬號體系中增加賬號密碼,配置如下:
打開C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\tomcat-users.xml
<role rolename="webdav"/><user username="root" password="root" roles="webdav"/>
提示:權限名稱必須和web.xml文件配置的一一對應。
完整的web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID" version="3.0"><display-name>webdav</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>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><servlet><servlet-name>webdav</servlet-name><servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class><init-param><param-name>debug</param-name><param-value>0</param-value></init-param><init-param><param-name>listings</param-name><param-value>true</param-value></init-param><!-- Read-Write Access Settings --><init-param><param-name>readonly</param-name><param-value>false</param-value></init-param></servlet><!-- URL Mapping --><servlet-mapping><servlet-name>webdav</servlet-name><url-pattern>/*</url-pattern></servlet-mapping><security-constraint><web-resource-collection><web-resource-name>webdav</web-resource-name><!-- Detect WebDAV Methods in URL For Whole Application --><url-pattern>/*</url-pattern><http-method>PROPFIND</http-method><http-method>PROPPATCH</http-method><http-method>COPY</http-method><http-method>MOVE</http-method><http-method>LOCK</http-method><http-method>UNLOCK</http-method></web-resource-collection><!-- Restrict access by role --><auth-constraint><role-name>*</role-name></auth-constraint></security-constraint><login-config><auth-method>BASIC</auth-method><realm-name>webdav</realm-name></login-config><security-role><description>WebDAV User</description><role-name>webdav</role-name></security-role> </web-app>
整個站點文件:鏈接:http://pan.baidu.com/s/1mit5KO4 密碼:ykkj
配置完成后,重啟Tomcat,然后訪問站點,出現如下樣式證明已經成功:
?
參考:
https://www.mulesoft.com/cn/tcat/tomcat-webdav(Tomcat配置)
https://my.oschina.net/liangrockman/blog/39462(Tomcat配置)
http://www.yiibai.com/article/enable-webdav-in-apache-server-2-2-x-windows.html(Apache的配置)