开发者

Can I respond to POST requests using Jetty's ResourceHandler?

Can I respond to POST requests using Jetty's ResourceHandler? If so, how?

For context, here's snippet configuring a file server using ResourceHandler from the Jetty tutorials:

public class FileServer
{
    public static void main(String[] args) throws Exception
    {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(8080);
        server.addConnector(connector);

        ResourceHandler resource_handler = new ResourceHandler();
        resource_handler.setDirectoriesListed(true);
        resource_handler.setWel开发者_JAVA百科comeFiles(new String[]{ "index.html" });

        resource_handler.setResourceBase(".");

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
        server.setHandler(handlers);

        server.start();
        server.join();
    }
}


The ResourceHandler seems to only support GET request. This makes sense, as the ResourceHandler only serves static resources (files, directories). A POST input would be discarded anyway.

I find it hard to make up a scenario, where one would need the ResourceHandler to reply to POST requests, but if you really want to achieve this, you could write your own Handler that wraps around the ResourceHandler and calls the GET methods for POST Requests. Some hints on how to do this can be found here: http://www.eclipse.org/jetty/documentation/current/writing-custom-handlers.html#passing-request-and-response

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜