WebDAV是一種超文本傳輸協議,Tomcat默認是支持WebDAV的,且默認爲禁用狀態。html
更多詳細信息,請參考:java
https://zh.wikipedia.org/wiki/WebDAVweb
http://www.webdav.org/apache
開啓步驟以下:windows
一、在Tomcat的webapps目錄下新建webdav文件夾,並在此文件夾下新建WEB-INF\web.xml文件tomcat
完整的文件目錄爲:C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\webdav\WEB-INF\web.xmlapp
配置Servlet,添加以下節點:yii
<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>
配置權限,添加以下節點:webapp
<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>爲自定義權限名稱。jsp
根據上面權限名稱,在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的配置)