nvelocity模板引擎

using NVelocity.App;
using NVelocity.Runtime;
using NVelocity;

VelocityEngine vltEngine = new VelocityEngine();
                vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));
                vltEngine.Init();

VelocityContext vltContext = new VelocityContext();
                vltContext.Put("username", "");
                vltContext.Put("password", "");
                vltContext.Put("msg","");

Template vltTemplate = vltEngine.GetTemplate("login.htm");
                System.IO.StringWriter vltWrite = new System.IO.StringWriter();
                vltTemplate.Merge(vltContext, vltWrite);

string html = vltWrite.GetStringBuilder().ToString();
                context.Response.Write(html);

上一篇:用“MEAN”技术栈开发web应用(三)用mongodb搭建数据库


下一篇:[Hadoop] - Win7下提交job到集群上去