2012-12-10 34 views
0

在控制器中,我有一個應該通過一個字符串名爲searchResultGraph.jsp將字符串傳遞給jsp,最新的錯誤?

@RequestMapping(value = PATHELEM + "/searchGraph") 
    public String handleGraph(Model model) { 
     String write = writer.getWriteString(); 
     model.addAttribute("write", write); 
     System.out.println(write); 
     return PATHELEM + "/searchResultGraph"; 
    } 

的JSP是這樣的JSP中的處理方法:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="core"%> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
     <title>Graph View</title> 
     <script type="text/javascript" src="<c:url value="/resources/js/json2.min.js" />"></script> <!-- ${pageContext.request.contextPath}/WebContent/WEB-INF/views/ --> 
     <script type="text/javascript" src="<c:url value="/resources/js/cytoscapeweb.min.js" />"></script> 
     <script type="text/javascript" src="<c:url value="/resources/js/AC_OETags.min.js" />"></script> 


     <script language="JavaScript"> 
      window.onload=function() { 
         // network data could alternatively be grabbed via ajax 
       var xml = '${write}'; 

         // init and draw 
         // initialization options 
          var options = { 
           swfPath: "CytoscapeWeb", 
           flashInstallerPath: "playerProductInstall" 
          }; 

          var vis = new org.cytoscapeweb.Visualization("cytoscapeweb", options); 

          var draw_options = { 
           // your data goes here 
           network: xml, 

           // show edge labels too 
           edgeLabelsVisible: false, 

           edgeTooltipsEnabled:true, 

           // let's try another layout 
           layout: "circle", 

           // hide pan zoom 
           panZoomControlVisible: true 
          }; 

          vis.draw(draw_options); 

         }; 
     </script> 

     <style> 
      /* The Cytoscape Web container must have its dimensions set. */ 
      html, body { height: 100%; width: 100%; padding: 0; margin: 0; } 
      #cytoscapeweb { width: 100%; height: 100%; } 
     </style> 
    </head> 
    <body> 
     <h1>The Graph</h1> 
     <h1>${write}</h1> 
     <div id="cytoscapeweb"> 
      Cytoscape Web will replace the contents of this div with your graph. 
      ${write} 
     </div> 
    </body> 
</html> 

但沒有什麼,當我嘗試顯示致電${write}。我的方法中是否有缺失?

謝謝!

+0

沒有什麼不對的,你在這裏給出的代碼。我只能要求你確保getWriteString()實際上返回一個非空字符串 –

+0

字符串不是空的......這將是一個簡單的解決方案! ;) – bethlis

+0

嘗試使用c:out代替。從邏輯上講,它不應該有所作爲,但你永遠不會知道..:P –

回答

0

好,我找到了解決方案:

options-tag中的鏈接也必須是相對鏈接!

所以不是這個

var options = { 
       swfPath: "CytoscapeWeb", 
       flashInstallerPath: "playerProductInstall" 
       }; 

我不得不寫:

var options = { 
       swfPath: "<c:url value="/resources/js/CytoscapeWeb" />", 
       flashInstallerPath: "<c:url value="resources/js/playerProductInstall" />" 
       }; 
0

檢查是否有一個方法命名爲getWriteString();在你bean類,如果不創建一個類的名字寫在你的控制器實例化一個名爲寫對象,然後通過一些字符串成,並添加到模型返回,通過您的控制器,

Write write = new Write(); 
write.getWriteString(); 
+0

我有一個名爲getWriteString()的方法;它會給我一些例外,如果我沒有它......唯一的問題是,他不顯示我的字符串。但它必須在某個地方,因爲如果不是,它會給我一個錯誤,如:沒有找到與名稱寫入的輸入 – bethlis

+0

嘗試使用'ModelMap'來代替。用'addObject()'方法 –