ECS to create our HTML elements
Import java.io.IOException;
Import Java.io.PrintWriter;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import ORG.APACHE.ECS.HTML.A;
Import Org.apache.ecs.html.BR;
Import Org.apache.ecs.html.Body;
Import Org.apache.ecs.html.Form;
Import Org.apache.ecs.html.Head;
Import org.apache.ecs.html.Html;
Import Org.apache.ecs.html.Input;
Import Org.apache.ecs.html.LI;
Import Org.apache.ecs.html.Label;
Import Org.apache.ecs.html.Meta;
Import Org.apache.ecs.html.TD;
Import Org.apache.ecs.html.TR;
Import org.apache.ecs.html.Table;
Import Org.apache.ecs.html.Title;
Import Org.apache.ecs.html.UL;
/**
* Use the ECS provided by Apache to create our HTML elements, usually with custom tags
* Requires ECS-1.4.2.jar support
* @author Lichuntao
*5 -
*/
Public class ecsservlet extends httpservlet {
Private static final longserialversionuid = 1L ;
Public void doget (httpservletrequest request, HttpServletResponse response)
throws servletexception, IOException {
/ * Set encoding and IO object * /
request. setcharacterencoding ("GBK");
response. setContentType ("TEXT/HTML;CHARSET=GBK");
PrintWriter PW = response. getwriter ();
/ * Build HTML pages and set related properties * /
HTML HTML = new html ();
/ * Build the head part of HTML * /
Head head = new Head ();
Head.addelement ( "ESC set title ");
Meta meta = new Meta ();
Meta.addattribute ("http-equiv", "Content-type");
Meta.addattribute ("content", "text/html; CHARSET=GBK ");
Head.addelement (meta);
/ * Build the body part of the HTML * /
Body BODY = new body ();
Body.addattribute ("style", "border:1px solid #cdcdcd");
Body.addattribute ("title", " i am the body of ECS " );
//table Part
Table table = new table ();
Table.addattribute ("id", "Esctableid");
TR tr = new tr ();
Tr.addattribute ("style", "background: #ebebeb");
Tr.addelement (new TD (" name "). AddAttribute ("width", "100px;" ));
Tr.addelement (new TD (" gender "). AddAttribute ("width" , "100px;" ));
Tr.addelement ( " Social Security number "). AddAttribute ("width", "100px;" ));
TR TR2 = new tr ();
Tr2.addelement (new TD (" Li Chuntao "));
Tr2.addelement (new TD (" male "));
Tr2.addelement ( new TD (). AddElement ( "www.baidu.com"). Addelementtoregistry ("230223199108203031" ));
Body.addelement (Table.addelement (TR). AddElement (TR2)). AddElement (new BR ());
//form Part
Form form = new form ();
Form.addattribute ("name", "Ecsform");
Form.addattribute ("action","testaction!to_ecs.action");
Form.addattribute ("method","POST");
UL ul = new ul ();
Ul.addattribute ("style", "List-style:none");
Li Liname = new Li ();
Liname.addelement (new Label (). Addelementtoregistry (" name:")). AddElement (new Input () addattribute ("name", "name"));
Li Ligender = new Li ();
Ligender.addelement (new Label (). Addelementtoregistry (" Age:")). AddElement (new Input (). AddAttribute ("name", "age");
Li Liidnumber = new Li ();
Liidnumber.addelement ("new Label (). Addelementtoregistry (" ID Number:")). AddElement (new Input () addattribute ("name", "IDNumber"));
Ul.addelement (Liname). AddElement (Ligender). AddElement (Liidnumber);
Body.addelement (Form.addelementtoregistry (UL));
/ * The elements are merged into a page * /
Html.addelement (head). AddElement (body);
Pw.print (HTML);
}
Public void doPost (httpservletrequest request, HttpServletResponse response)
throws servletexception, IOException {
Doget (request,response);
}
ECS to create our HTML elements