|
|
@@ -2,6 +2,7 @@ package cn.hutool.http.server.action;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.lang.Console;
|
|
|
import cn.hutool.http.server.HttpServerRequest;
|
|
|
import cn.hutool.http.server.HttpServerResponse;
|
|
|
|
|
|
@@ -18,7 +19,7 @@ public class RootAction implements Action {
|
|
|
|
|
|
public static final String DEFAULT_INDEX_FILE_NAME = "index.html";
|
|
|
|
|
|
- private final String rootDir;
|
|
|
+ private final File rootDir;
|
|
|
private final List<String> indexFileNames;
|
|
|
|
|
|
/**
|
|
|
@@ -27,6 +28,15 @@ public class RootAction implements Action {
|
|
|
* @param rootDir 网页根目录
|
|
|
*/
|
|
|
public RootAction(String rootDir) {
|
|
|
+ this(new File(rootDir));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造
|
|
|
+ *
|
|
|
+ * @param rootDir 网页根目录
|
|
|
+ */
|
|
|
+ public RootAction(File rootDir) {
|
|
|
this(rootDir, DEFAULT_INDEX_FILE_NAME);
|
|
|
}
|
|
|
|
|
|
@@ -37,6 +47,17 @@ public class RootAction implements Action {
|
|
|
* @param indexFileNames 主页文件名列表
|
|
|
*/
|
|
|
public RootAction(String rootDir, String... indexFileNames) {
|
|
|
+ this(new File(rootDir), indexFileNames);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造
|
|
|
+ *
|
|
|
+ * @param rootDir 网页根目录
|
|
|
+ * @param indexFileNames 主页文件名列表
|
|
|
+ * @since 5.4.0
|
|
|
+ */
|
|
|
+ public RootAction(File rootDir, String... indexFileNames) {
|
|
|
this.rootDir = rootDir;
|
|
|
this.indexFileNames = CollUtil.toList(indexFileNames);
|
|
|
}
|
|
|
@@ -59,6 +80,7 @@ public class RootAction implements Action {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ Console.log(file.getAbsolutePath());
|
|
|
response.send404("404 Not Found !");
|
|
|
}
|
|
|
}
|