您的位置:首页 > 其它

xloadtree Demo本地使用问题

2005-10-12 01:18 363 查看
xloadtree的Demo可以从http://webfx.eae.net/dhtml/xloadtree/xloadtree.html下载,并有usage,api...
将xloadtree的Demo直接放置到Tomcat的Webapps目录下,不能正确显示,总显示“Error Load tree.xml”,一步步对问题进行了跟踪,找到了问题的所在。问题在于XmlHttp使用了responseXML,返回的消息必须是xml,更准确的说是必须能够被识别为xml,要做到这点其实很简单,只要设置ContentType="test/xml"。
我的做法是对xml用jsp进行了包装:
tree.xml <?xml version="1.0" encoding="UTF-8"?>
<tree>
<tree text="Load "tree1.xml"" src="tree1.xml" />
<tree text="Loaded Item 1" action="http://webfx.eae.net" />
<tree text="Loaded Item 2">
<tree text="Loaded Item 2.1" action="javascript:alert(2.1)" />
</tree>
<tree text="Loaded Item 3 (with target)" action="http://www.google.com" target="_new" />
<tree text="Load "tree1.xml"" src="tree1.xml" />
</tree>

tree.jsp <%
response.setContentType("text/xml");
out.println("<?xml version=/"1.0/" encoding=/"UTF-8/"?>/n" +
"/n" +
"<tree>/n" +
"/t<tree text=/"Load "tree1.xml"/" src=/"tree1.jsp/" />/n" +
"/t<tree text=/"Loaded Item 1/" action=/"http://webfx.eae.net/" />/n" +
"/t<tree text=/"Loaded Item 2/">/n" +
"/t/t<tree text=/"Loaded Item 2.1/" action=/"javascript:alert(2.1)/" />/n" +
"/t</tree>/n" +
"/t<tree text=/"Loaded Item 3 (with target)/" action=/"http://www.google.com/" target=/"_new/" />/n" +
"/t<tree text=/"Load "tree1.xml"/" src=/"tree1.jsp/" />/n" +
"</tree>");
%>

tree1.xml <?xml version="1.0"?>
<tree>
<tree text="Loads tree2.xml" src="tree2.xml"/>
<tree text="Loads NOT_AVAILABLE.xml" src="NOT_AVAILABLE.xml"
icon="images/xp/folder.png"/>
<tree text="Loads emptytree.xml" src="emptytree.xml"
icon="images/xp/folder.png"/>
<tree text="Loaded Item 3" action="javascript:alert(3)" />
<tree text="Loaded Item 4" action="javascript:alert(4)">
<tree text="Loaded Item 4.1" action="javascript:alert(2.1)" />
<tree text="Loaded Item 4.2">
<tree text="Loaded Item 4.2.1">
<tree text="Loaded Item 4.2.1.2"/>
<tree text="Loaded Item 4.2.1.3"/>
</tree>
<tree text="Loaded Item 4.2.2"/>
</tree>
</tree>
<tree text="WebFX Home" action="http://webfx.eae.net"
icon="http://webfx.eae.net/images/favicon.gif"/>
</tree>

tree1.jsp <%
response.setContentType("text/xml");
out.println("<?xml version=/"1.0/"?>/n" +
"/n" +
"<tree>/n" +
"/t<tree text=/"Loads tree2.xml/" src=/"tree2.jsp/"/>/n" +
"/t<tree text=/"Loads NOT_AVAILABLE.xml/" src=/"NOT_AVAILABLE.xml/"/n" +
"/t/ticon=/"images/xp/folder.png/"/>/n" +
"/t<tree text=/"Loads emptytree.xml/" src=/"emptytree.jsp/"/n" +
"/t/ticon=/"images/xp/folder.png/"/>/n" +
"/t<tree text=/"Loaded Item 3/" action=/"javascript:alert(3)/" />/n" +
"/t<tree text=/"Loaded Item 4/" action=/"javascript:alert(4)/">/n" +
"/t/t<tree text=/"Loaded Item 4.1/" action=/"javascript:alert(2.1)/" />/n" +
"/t/t<tree text=/"Loaded Item 4.2/">/n" +
"/t/t/t<tree text=/"Loaded Item 4.2.1/">/n" +
"/t/t/t/t<tree text=/"Loaded Item 4.2.1.2/"/>/n" +
"/t/t/t/t<tree text=/"Loaded Item 4.2.1.3/"/>/n" +
"/t/t/t</tree>/n" +
"/t/t/t<tree text=/"Loaded Item 4.2.2/"/>/n" +
"/t/t</tree>/n" +
"/t</tree>/n" +
"/t<tree text=/"WebFX Home/" action=/"http://webfx.eae.net/"/n" +
"/t/ticon=/"/n">http://webfx.eae.net/images/favicon.gif/"/>/n" +
"</tree>");
%>

tree2.xml <?xml version="1.0"?>
<tree>
<tree text="Loaded File 2 Item 1" action="javascript:alert(1)" />
<tree text="Loaded File 2 Item 2" action="javascript:alert(2)">
<tree text="Loaded File 2 Item 2.1" action="javascript:alert(2.1)" />
<tree text="Loaded File 2 Item 2.2 (LOOP)" src="tree1.xml" action="javascript:alert(2.1)" />
</tree>
<tree text="Loaded File 2 Item 3" action="javascript:alert(3)" />
</tree>

tree2.jsp <%
response.setContentType("text/xml");
out.println("<?xml version=/"1.0/"?>/n" +
"/n" +
"<tree>/n" +
"/t<tree text=/"Loaded File 2 Item 1/" action=/"javascript:alert(1)/" />/n" +
"/t<tree text=/"Loaded File 2 Item 2/" action=/"javascript:alert(2)/">/n" +
"/t/t<tree text=/"Loaded File 2 Item 2.1/" action=/"javascript:alert(2.1)/" />/n" +
"/t/t<tree text=/"Loaded File 2 Item 2.2 (LOOP)/" src=/"tree1.jsp/" action=/"javascript:alert(2.1)/" />/n" +
"/t</tree>/n" +
"/t<tree text=/"Loaded File 2 Item 3/" action=/"javascript:alert(3)/" />/n" +
"</tree>");
%>

emptytree.xml <?xml version="1.0"?>
<tree/>

emptytree.jsp <%
response.setContentType("text/xml");
out.println("<?xml version=/"1.0/"?>/n" +
"<tree/>");
%>

这样就能够正确的显示树图了,这种方法比较适合动态的通过程序获取树图。
还有种比较彻底的办法,更改xloadtree关于xmlhttp的部分。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: