public class SimpleServer extends Object
HttpServer| Constructor and Description |
|---|
SimpleServer(InetSocketAddress address)
构造
|
SimpleServer(InetSocketAddress address,
SSLContext sslContext)
构造
|
SimpleServer(int port)
构造
|
SimpleServer(String hostname,
int port)
构造
|
| Modifier and Type | Method and Description |
|---|---|
SimpleServer |
addAction(String path,
HttpHandler action)
增加请求处理规则,使用默认的
RootHandler,默认从当前项目根目录读取页面 |
SimpleServer |
addFilter(com.sun.net.httpserver.Filter filter)
增加请求过滤器,此过滤器对所有请求有效
此方法需在以下方法前之前调用: setRoot(File)
setRoot(String)
createContext(String, HttpHandler)
addHandler(String, HttpHandler)
|
SimpleServer |
addFilter(HttpFilter filter)
增加请求过滤器,此过滤器对所有请求有效
此方法需在以下方法前之前调用: setRoot(File)
setRoot(String)
createContext(String, HttpHandler)
addHandler(String, HttpHandler)
|
SimpleServer |
addHandler(String path,
com.sun.net.httpserver.HttpHandler handler)
增加请求处理规则
|
com.sun.net.httpserver.HttpContext |
createContext(String path,
com.sun.net.httpserver.HttpHandler handler)
创建请求映射上下文,创建后,用户访问指定路径可使用
HttpHandler 中的规则进行处理 |
InetSocketAddress |
getAddress()
获取服务器地址信息
|
com.sun.net.httpserver.HttpServer |
getRawServer()
获得原始HttpServer对象
|
SimpleServer |
setExecutor(Executor executor)
设置自定义线程池
|
SimpleServer |
setRoot(File root)
设置根目录,默认的页面从root目录中读取解析返回
|
SimpleServer |
setRoot(String root)
设置根目录,默认的页面从root目录中读取解析返回
|
void |
start()
启动Http服务器,启动后会阻塞当前线程
|
public SimpleServer(int port)
port - 监听端口public SimpleServer(String hostname, int port)
hostname - 监听地址port - 监听端口public SimpleServer(InetSocketAddress address)
address - 监听地址public SimpleServer(InetSocketAddress address, SSLContext sslContext)
address - 监听地址sslContext - ssl配置public SimpleServer addFilter(com.sun.net.httpserver.Filter filter)
filter - Filter 请求过滤器public SimpleServer addFilter(HttpFilter filter)
filter - Filter 请求过滤器public SimpleServer addHandler(String path, com.sun.net.httpserver.HttpHandler handler)
path - 路径,例如:/a/b 或者 a/bhandler - 处理器,包括请求和响应处理createContext(String, HttpHandler)public com.sun.net.httpserver.HttpContext createContext(String path, com.sun.net.httpserver.HttpHandler handler)
HttpHandler 中的规则进行处理path - 路径,例如:/a/b 或者 a/bhandler - 处理器,包括请求和响应处理HttpContextpublic SimpleServer addAction(String path, HttpHandler action)
RootHandler,默认从当前项目根目录读取页面path - 路径,例如:/a/b 或者 a/baction - 处理器,包括请求和响应处理public SimpleServer setRoot(String root)
root - 路径public SimpleServer setRoot(File root)
root - 路径public SimpleServer setExecutor(Executor executor)
executor - Executorpublic com.sun.net.httpserver.HttpServer getRawServer()
HttpServerpublic InetSocketAddress getAddress()
InetSocketAddresspublic void start()
Copyright © 2025. All rights reserved.