Tomcat7/8开启WebDAV的支持
WebDAV是一種超文本傳輸協(xié)議,Tomcat默認(rèn)是支持WebDAV的,且默認(rèn)為禁用狀態(tài)。
更多詳細(xì)信息,請參考:
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,添加如下節(jié)點:
<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>配置權(quán)限,添加如下節(jié)點:
<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>為自定義權(quán)限名稱。
根據(jù)上面權(quán)限名稱,在Tomcat賬號體系中增加賬號密碼,配置如下:
打開C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\tomcat-users.xml
<role rolename="webdav"/><user username="root" password="root" roles="webdav"/>提示:權(quán)限名稱必須和web.xml文件配置的一一對應(yīng)。
完整的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,然后訪問站點,出現(xiàn)如下樣式證明已經(jīng)成功:
?
參考:
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的配置)
總結(jié)
以上是生活随笔為你收集整理的Tomcat7/8开启WebDAV的支持的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vim 分割窗口
- 下一篇: VC6获取硬盘序列号、型号、修订版本号