2009-09-26

How to display a directory listing in Google App Engine

Google App Engine is really not meant to serve up a lot of static content; but sometimes you just want to!

If you put a directory full of stuff into your web archive and point your browser at it, AppEngine will tell you there's nothing there. It's possible to change that, though.

The following instructions are for the Java incarnation of AppEngine; I would imagine you can do something equivalent in the Python engine, but I don't know any details.
  • Make sure your directory and its children are marked as "static" in appengine-web.xml :
  • style-span" style="font-family: 'Times New Roman'; font-weight: normal;">Map your directory to Jetty's default servlet within web.xml :
    <static-files>
          <include path="/*.css"/>
          <include path="/favicon.ico"/>
          <include path="/code/**"/>
       </static-files>
    
  • Next, tell Jetty in web.xml to accept directory requests:
    <context-param>
          <param-name>org.mortbay.jetty.servlet.Default.dirAllowed</param-name>
          <param-value>true</param-value>
    </context-param>
    
  • Finally, define Jetty's "default" servlet in web.xml to accept directory requests:
    <servlet>
          <servlet-name>default</servlet-name>
          <servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
          <init-param>
             <param-name>acceptRanges</param-name><param-value>true</param-value>
          </init-param>
          <init-param>
             <param-name>dirAllowed</param-name><param-value>true</param-value>
          </init-param>
          <load-on-startup>0
       </servlet>
    
       <servlet-mapping>
          <servlet-name>default</servlet-name>
          <url-pattern>/code/*</url-pattern>
       </servlet-mapping>
    

  


... and that's more or less it!

No comments: