public class SimpleServer extends Object
HttpServer
Constructor and Description |
---|
SimpleServer(InetSocketAddress address)
构造
|
SimpleServer(InetSocketAddress address,
com.sun.net.httpserver.HttpsConfigurator configurator)
构造
|
SimpleServer(int port)
构造
|
SimpleServer(String hostname,
int port)
构造
|
Modifier and Type | Method and Description |
---|---|
SimpleServer |
addAction(String path,
Action action)
增加请求处理规则
|
SimpleServer |
addFilter(com.sun.net.httpserver.Filter filter)
增加请求过滤器,此过滤器对所有请求有效
此方法需在以下方法前之前调用: setRoot(File)
setRoot(String)
createContext(String, HttpHandler)
addHandler(String, HttpHandler)
addAction(String, Action)
|
SimpleServer |
addFilter(HttpFilter filter)
增加请求过滤器,此过滤器对所有请求有效
此方法需在以下方法前之前调用: setRoot(File)
setRoot(String)
createContext(String, HttpHandler)
addHandler(String, HttpHandler)
addAction(String, Action)
|
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, com.sun.net.httpserver.HttpsConfigurator configurator)
address
- 监听地址configurator
- https配置信息,用于使用自定义SSL(TLS)证书等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
- 处理器,包括请求和响应处理HttpContext
public SimpleServer setRoot(String root)
root
- 路径public SimpleServer setRoot(File root)
root
- 路径public SimpleServer addAction(String path, Action action)
path
- 路径action
- 处理器public SimpleServer setExecutor(Executor executor)
executor
- Executor
public com.sun.net.httpserver.HttpServer getRawServer()
HttpServer
public InetSocketAddress getAddress()
InetSocketAddress
public void start()
Copyright © 2024. All rights reserved.