Search code examples
ajaxapacheapache-config

Apache Server File Permission


I am using Apache Server 6.0 and I am trying to update a file using ajax put request but the server is giving me error 405 Method Not Allowed. I am working this out on windows. Can anybody help me out if that.

Thanks in Advance.

Vinay


Solution

  • I'm assuming you are using apache tomcat (because you have mentioned version 6.0)

    In that case add this to your webapp's web.xml:

    <servlet>
        <servlet-name>myDefault</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</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>false</param-value>
        </init-param>
        <init-param>
            <param-name>readonly</param-name>
            <param-value>false</param-value> <!-- this will enable PUT for your app -->
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>myDefault</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    

    Then you can test this like so, to upload the file (You need the curl program to test)

    curl -T somefile.txt http://localhot:8080/<yourapp>/
    

    If you want to enable this globally, you can make the same change in /conf/web.xml (for default servlet)