直接打开时显示Simile时间轴,而不是由servlet打开时显示

时间:2013-06-27 03:16:08

标签: java javascript servlets timeline simile

基本上我有一个servlet打开一个使用明喻时间轴小部件的页面timeline.html。 当直接从user.dir / timeline.html打开网页时,时间线显示完美。 但是当localhost:8080上的servlet打开网页时,它不会加载xml文件。

你知道为什么吗?

if (action.equals("create")) {
             request.getRequestDispatcher("/timeline.html").forward(request, response); }   

时间轴代码:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Timeline</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
 <script src="http://api.simile-widgets.org/timeline/2.3.1/timeline-api.js?bundle=true" type="text/javascript"></script>
 <script>
   function onLoad() {
   var eventSource = new Timeline.DefaultEventSource();
  var bandInfos = [
 Timeline.createBandInfo({
     eventSource:    eventSource,
     date:           "Jun 28 2013 00:00:00 GMT",
     width:          "70%", 
     intervalUnit:   Timeline.DateTime.MONTH, 
     intervalPixels: 100
 }),
 Timeline.createBandInfo({
     overview:       true,
     eventSource:    eventSource,
     date:           "Jun 28 2013 00:00:00 GMT",
     width:          "30%", 
     intervalUnit:   Timeline.DateTime.YEAR, 
     intervalPixels: 200
 })
 ];
 bandInfos[1].syncWith = 0;
 bandInfos[1].highlight = true;

 tl = Timeline.create(document.getElementById("my-timeline"), bandInfos);
 Timeline.loadXML("/timeline.xml", function(xml, url) { eventSource.loadXML(xml, url); });}
  </script>
  </head>
  <body onload="onLoad();" onresize="onResize();">
   <div id="my-timeline" style="height: 300px; border: 1px solid #aaa"></div>
   <noscript>
This page uses Javascript to show you a Timeline. Please enable Javascript in your browser to see the full page. Thank you.
</noscript>

1 个答案:

答案 0 :(得分:2)

/timeline.xml指的是您的Web应用程序上下文根位置。你是否将xml文件放在根位置。例如,如果您在myapp部署了名为webapps/myapp的网络应用程序,则'/'会引用myapp目录。因此/timeline.xml是指myapp/timeline.xml