当前位置: 首页 > 工具软件 > Milton > 使用案例 >

基于Milton的webdav解决方案 - Test

丁弘新
2023-12-01
建立目录 d:\test
新建网络邻居 http://127.0.0.1:8080/webdav

就可以了。


package com.scs;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;

import com.bradmcevoy.http.DefaultResponseHandler;
import com.bradmcevoy.http.HttpManager;
import com.bradmcevoy.http.ServletRequest;
import com.bradmcevoy.http.ServletResponse;

import com.ettrema.http.fs.FileSystemResourceFactory;

public class UserStorage {
static public void main(String[] args) throws Exception {
Server server = new Server(8080);

Context context = new Context(server,"/");

context.addServlet( new ServletHolder( new HelloServlet()), "/*");
context.setAllowNullPathInfo(true);

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

public static class HelloServlet extends HttpServlet
{
FileSystemResourceFactory factory = new FileSystemResourceFactory();
HttpManager http = new HttpManager(factory, new DefaultResponseHandler("1,2"));
public HelloServlet() {
File file = new File("d:\\test");
factory.setRoot( file );
}

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
ServletRequest req = new ServletRequest(request);
ServletResponse resp = new ServletResponse(response);
http.process( req, resp );
}
}

}
 类似资料: