This commit is contained in:
@@ -156,8 +156,9 @@
|
|||||||
<!--
|
<!--
|
||||||
当Server为HTTP协议时,ResourceServlet才有效. 默认存在一个有默认属性的resource-servlet节点
|
当Server为HTTP协议时,ResourceServlet才有效. 默认存在一个有默认属性的resource-servlet节点
|
||||||
webroot: web资源的根目录, 默认取server节点中的root值
|
webroot: web资源的根目录, 默认取server节点中的root值
|
||||||
|
index : 启始页,默认值:index.html
|
||||||
-->
|
-->
|
||||||
<resource-servlet webroot="root">
|
<resource-servlet webroot="root" index="index.html">
|
||||||
<!--
|
<!--
|
||||||
资源缓存的配置, 默认存在一个含默认属性的caches节点
|
资源缓存的配置, 默认存在一个含默认属性的caches节点
|
||||||
limit: 资源缓存最大容量, 默认: 0, 为0表示不缓存, 单位可以是B、K、M、G,不区分大小写
|
limit: 资源缓存最大容量, 默认: 0, 为0表示不缓存, 单位可以是B、K、M、G,不区分大小写
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ public final class HttpResourceServlet extends HttpServlet {
|
|||||||
|
|
||||||
protected File root = new File("./root/");
|
protected File root = new File("./root/");
|
||||||
|
|
||||||
|
protected String indexHtml = "index.html";
|
||||||
|
|
||||||
protected final ConcurrentHashMap<String, FileEntry> files = new ConcurrentHashMap<>();
|
protected final ConcurrentHashMap<String, FileEntry> files = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
protected final ConcurrentHashMap<WatchKey, Path> keymaps = new ConcurrentHashMap<>();
|
protected final ConcurrentHashMap<WatchKey, Path> keymaps = new ConcurrentHashMap<>();
|
||||||
@@ -104,6 +106,7 @@ public final class HttpResourceServlet extends HttpServlet {
|
|||||||
public void init(HttpContext context, AnyValue config) {
|
public void init(HttpContext context, AnyValue config) {
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
String rootstr = config.getValue("webroot", "root");
|
String rootstr = config.getValue("webroot", "root");
|
||||||
|
this.indexHtml = config.getValue("index", "index.html");
|
||||||
if (rootstr.indexOf(':') < 0 && rootstr.indexOf('/') != 0 && System.getProperty("APP_HOME") != null) {
|
if (rootstr.indexOf(':') < 0 && rootstr.indexOf('/') != 0 && System.getProperty("APP_HOME") != null) {
|
||||||
rootstr = new File(System.getProperty("APP_HOME"), rootstr).getPath();
|
rootstr = new File(System.getProperty("APP_HOME"), rootstr).getPath();
|
||||||
}
|
}
|
||||||
@@ -178,7 +181,9 @@ public final class HttpResourceServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uri.length() == 0 || uri.equals("/")) uri = "/index.html";
|
if (uri.length() == 0 || uri.equals("/")) {
|
||||||
|
uri = this.indexHtml.indexOf('/') == 0 ? this.indexHtml : ("/" + this.indexHtml);
|
||||||
|
}
|
||||||
//System.out.println(request);
|
//System.out.println(request);
|
||||||
FileEntry entry;
|
FileEntry entry;
|
||||||
if (watchThread == null) {
|
if (watchThread == null) {
|
||||||
@@ -195,8 +200,10 @@ public final class HttpResourceServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private FileEntry createFileEntry(String uri) {
|
private FileEntry createFileEntry(String uri) {
|
||||||
File file = new File(root, uri);
|
File rfile = new File(root, uri);
|
||||||
if (file.isDirectory()) file = new File(file, "index.html");
|
File file = rfile;
|
||||||
|
if (file.isDirectory()) file = new File(rfile, this.indexHtml);
|
||||||
|
if (file.isDirectory()) file = new File(rfile, "index.html");
|
||||||
if (!file.isFile() || !file.canRead()) return null;
|
if (!file.isFile() || !file.canRead()) return null;
|
||||||
FileEntry en = new FileEntry(this, file);
|
FileEntry en = new FileEntry(this, file);
|
||||||
if (watchThread == null) return en;
|
if (watchThread == null) return en;
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public final class HttpServer extends Server<String, HttpContext, HttpRequest, H
|
|||||||
@Override
|
@Override
|
||||||
public void init(AnyValue config) throws Exception {
|
public void init(AnyValue config) throws Exception {
|
||||||
super.init(config);
|
super.init(config);
|
||||||
AnyValue conf = config == null ? null : config.getAnyValue("servlets");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHttpServlet(HttpServlet servlet, final String prefix, AnyValue conf, String... mappings) {
|
public void addHttpServlet(HttpServlet servlet, final String prefix, AnyValue conf, String... mappings) {
|
||||||
|
|||||||
Reference in New Issue
Block a user