67,541
社区成员
发帖
与我相关
我的任务
分享
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws IOException {
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
PrintWriter outt = response.getWriter();
String id = request.getParameter("bmid");
Document doc = new Document(new Element("tree"));
if (id == null) {
List depts=serviceF.getDepartmentDAO().findAll(); /获得部门信息
transferd(doc, depts);
} else {
Long sid=Long.parseLong(id);
List lists=serviceF.getSectionDAO().findByBmid(sid); //获得科室信息
transfers(doc, lists);
}
Format format = Format.getCompactFormat();
format.setEncoding("UTF-8");
format.setIndent("\t");
XMLOutputter xout = new XMLOutputter(format);
xout.output(doc, outt);
outt.flush();
outt.close();
return mapping.getInputForward();
}
private void transferd(Document doc, List list) {
for(Iterator it=list.iterator();it.hasNext();)
{
Department dept=(Department)it.next();
Element tree=doc.getRootElement();
Element inner=new Element("tree").setAttribute("text",dept.getBmmc());
if(it.hasNext())
inner.setAttribute("src","<%=request.getContextPath()%>/organization_View.do?bmid="+dept.getBmid());
inner.setAttribute("action","#");
tree.addContent(inner);
}
}
private void transfers(Document doc, List list) {
for(Iterator it=list.iterator();it.hasNext();)
{
Section sec=(Section)it.next();
Element tree=doc.getRootElement();
Element inner=new Element("tree").setAttribute("text",sec.getKsmc());
tree.addContent(inner);
if(it.hasNext())
inner.setAttribute("src","/organization_View?ksid="+sec.getKsid());
inner.setAttribute("action","");
}
}