特殊的输出
1.输出文件或图片
File file = new File("F:fzxm1.jpg");
hoContext.httpResponse.resFilePrint(file,0,file.length());
2.bufferedImage输出
3.字节输出
4.长连接输出
前后台建立连接后保持连接,可双向收发消息,用来做后台长时间任务处理时向前端发送任务完成进度消息(前端实现进度条显示),即时通信等,使用方式如下
- 创建模块和项目(参照2.3.2 JAVA高阶API开发方法)
- 模块类形参设置为WsContext()
-
WsContext定义如下表所示
datas 成员变量/map结构 前端传递的数据 DataActions 成员变量 数据库操作对象 resPrint(String res) 成员方法 用来输出数据到浏览器 用例 package dynamic;
import microbee.http.apps.dynamic.WsContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
public class Testws {
public void test (WsContext wsContext){
String name = (String)wsContext.datas.get("name");
wsContext.resPrint("1");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
wsContext.resPrint("2");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
wsContext.resPrint("3");
}
}
- API测试方法:浏览器访问/wc.html进行测试
- 特别说明:该方法实现的接口不能通过http协议访问,只能通过wc协议访问,且定义url不能与http接口冲突。
本文档来自—microbee-http 丨 软件开发框架平台
扫一扫