日期:2014-05-16 浏览次数:20327 次
还未完全开发完,不过目前基本功能已经完成了,先记录一下
最新版开始支持nodejs, 支持类似于j2ee的开发方式, servlet, jsp等
webserver.js, 类似于jsp/servlet容器,可以运行js版的servlet, jsp
示例代码:
var os = require("os"); var fs = require("fs"); var http = require("http"); var URL = require("url"); var july = require("./webserver.js"); var servletContext = new july.ServletContext(); servletContext.home = "webapp"; servletContext.path = "/test1"; servletContext.set("test1", "/test1", function(request, response, servletChain){ response.write("test1: Hello World !"); servletChain.doChain(request, response); }); servletContext.set("test2", "(/test1)|(/test2)", function(request, response, servletChain){ response.write("test2: Hello World !"); }); servletContext.set("test3", "/test3", function(request, response, servletChain){ var userList = []; for(var i = 0; i < 20; i++) { userList.push({"name": "tome" + i, "sex": 1, "birthday": new Date}); } request.setAttribute("pageNum", 1); request.setAttribute("pageSize", 20); request.setAttribute("total", 373); request.setAttribute("userList", userList); request.getRequestDispatcher("/test.jsp").forward(request, response, servletChain); }); var webApplication = new july.WebApplication(); webApplication.servletContext = servletContext; var server = http.createServer(function(request, response){ console.log("request.url: " + request.url); webApplication.dispatch(request, response); }); server.listen(80, "localhost");虚拟主机支持:
var webApplication = new july.WebApplication(); webApplication.servletContext = servletContext; server.listen(80, "localhost"); var webServer = new july.WebServer(); var vistualHost = new july.VistualHost("(www\.mytest\.com)|(mytest\.com)"); vistualHost.add("/test", webApplication); var server = http.createServer(function(request, response){ console.log("request.url: " + request.url); webServer.dispatch(request, response); });
目前支持的功能
1. 一个server下可以添加多个虚拟主机,可以给每个虚拟主机设定域名,多应用绑定,一个虚拟主机下可以添加多个应用
2. jsp/servlet支持, 可以采用类似servlet/jsp的方式开发,servlet作为控制层,jsp作为展现层