Dynamic Tree example
JSP page source code:
<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML>
Key code of struts2 action:
@Override public String execute() throws Exception { String data = "<li>Item 1<ul><li>Item 1.1</li></ul></li><li>Item 2<ul>" + "<li>Item 2.1 <ul><li>Item 2.1.1</li><li>Item 2.1.2</li></ul></li>" + "<li>Item 2.2</li></ul></li><li>Item 3</li>"; ServletActionContext.getResponse().getWriter().write(data); return null; }
Struts. xml configuration:
<! -- The following two configurations can run normally. Why? --> <Package name = "ajax" extends = "JSON-Default"> <action name = "Manual" class = "com. test. manualaction "> <result type =" JSON "> </result> </Action> </package> <package name =" server "extends =" struts-Default "> <action name = "Manual" class = "com. test. manualaction "> <result>/MSG. JSP </result> </Action> </package>