ASP. Output Object Properties (Entity Association) of the dynamic page static

Source: Internet
Author: User

ASP. Output Object Properties (Entity Association) of the dynamic page static

The template engine not only outputs a single piece of data, but also outputs the properties of the object directly

Using system;using system.collections.generic;using system.linq;using system.web;using NVelocity.Runtime;using Nvelocity;using nvelocity.app;namespace czbk{///<summary>//Handler2 Summary description///</summary> Publ IC class Handler2:ihttphandler {public void ProcessRequest (HttpContext context) {CONTEXT.R Esponse.            ContentType = "text/html";//plain indicates that normal text format output static should output HTML format text User user = new user (); User.            Username = "King Sledgehammer"; User.            Userphone = "18312345678";            Role role = new role (); Role.            Roleid = "1001"; Role.            Rolename = "Super Funny King"; User.            User_role1 = role;//Assigns a value velocityengine vltengine = new Velocityengine () to the associated object;            Vltengine.setproperty (Runtimeconstants.resource_loader, "file"); Vltengine.setproperty (Runtimeconstants.file_resource_loader_path, System.Web.Hosting.HostingEnvironment.MapPath ("~/"));/           /template file is located in the directory Vltengine.init (); Velocitycontext vltcontext = new Velocitycontext (); Vltcontext.put ("U", user);//Set the number of parameters.            Template vlttemplate = vltengine.gettemplate ("users.htm") can be referenced through $u in templates;            System.IO.StringWriter vltwriter = new System.IO.StringWriter ();            Vlttemplate.merge (Vltcontext, Vltwriter); String html = Vltwriter.getstringbuilder ().            ToString (); Context.        Response.Write (HTML);            } public bool IsReusable {get {return false;        }}} public class User {private string username;            public string Username {get {return Username;}        set {username = value;}        } private string Userphone;            public string Userphone {get {return userphone;}        set {Userphone = value;} The private role user_role;//introduces an associated class object public Role User_role1 {get {return user_role;        } set {user_role = value;}        }} public class Role {private string Roleid;            public string Roleid {get {return roleid;}        set {Roleid = value;}        } private string RoleName;            public string Rolename {get {return Rolename;}        set {rolename = value;} }    }}


Front Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.