WebDAV是一种超文本传输协议,Tomcat默认是支持WebDAV的,且默认为禁用状态。
更多详细信息,请参考:
https://zh.wikipedia.org/wiki/WebDAV
开启步骤如下:
1、在Tomcat的webapps目录下新建webdav文件夹,并在此文件夹下新建WEB-INFweb.xml文件
完整的文件目录为:C:Program FilesApache Software FoundationTomcat 7.0webappswebdavWEB-INFweb.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 FilesApache Software FoundationTomcat 7.0conftomcat-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的配置)