Struts2.method
Public String Stat () {// fixed two-sentence actioncontext CTX = actioncontext. getcontext (); httpservletrequest request = (httpservletrequest) CTX. get (servletactioncontext. http_request); List <News> weeklist = new arraylist <News> (); // weekly list <News> monthlist = new arraylist <News> (); // monthly list <News> quarterlist = new arraylist <News> (); // quarterly request. setattribute ("Week", weeklist. size (); Request. setattribute ("month", monthlist. size (); Request. setattribute ("quarter", quarterlist. size (); Return "stat ";}
JSP. jsp
<% @ Page contenttype = "text/html" pageencoding = "UTF-8" %> <% stringbuffer content = new stringbuffer (""); content. append ("<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> "); Content. append ("<roots>"); content. append ("<week>"); content. append (request. getattribute ("Week"); content. append ("</week>"); content. append ("<month>"); content. append (request. getattribute ("month"); content. append ("</month>"); content. append ("<quarter>"); content. append (request. getattribute ("quarter"); content. append ("</quarter>"); content. append ("</roots>"); response. setcharacterencoding ("UTF-8"); out. print (content); %>
Display. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Roots> <week> 47 </week> <month> 22 </month> <quarter> 22 </quarter> </roots>