Serving large-size static files with Jetty

时间:2019-04-23 15:13:15

标签: jetty

I have a Jetty server, which I want to use to server a large-size static files.

I have edited "jetty.xml" adding the following:

<Set name="handler">
    <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
      <Set name="handlers">
        <Array type="org.eclipse.jetty.server.Handler">
          <Item>
            <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
              <Set name="handlers">
                <Array type="org.eclipse.jetty.server.handler.ContextHandler">
                  <Item>
                    <New class="org.eclipse.jetty.server.handler.ContextHandler">
                      <Set name="contextPath">/files</Set>
                      <Set name="handler">
                        <New class="org.eclipse.jetty.server.handler.ResourceHandler">
                          <Set name="directoriesListed">false</Set>
                          <Set name="resourceBase">/path/to/my/files</Set>
                        </New>
                      </Set>
                    </New>
                  </Item>
                </Array>
              </Set>
            </New>
          </Item>
          <Item>
            <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
          </Item>
        </Array>
      </Set>
    </New>
  </Set>

It works pretty fine with small files, but with large files the download is too slow and in many times doesn't complete. I'm using Jetty version 9.2.13, and a web browser as the client.

According to "Do not use ResourceHandler to serve static files, use DefaultServlet": https://github.com/perwendel/spark/issues/316

I want to use DefaultServlet in my xml instead of ResourceHandler, but I don't know how?

Any help?

0 个答案:

没有答案
相关问题