xloadtree Demo本地使用问题

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 &quot;tree1.xml&quot;" 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 &quot;tree1.xml&quot;" 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 &quot;tree1.xml&quot;/" 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 &quot;tree1.xml&quot;/" 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的部分。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值