2013-04-23 73 views
0

使用我這裏The function " " must be used with a prefix when a default namespace is not specified類似的問題問。但是我的背景是不同的。功能必須aprefix -jsp

我有彈簧web應用程序包含一個jsp其獲取來自控制器創建的對象(使用幫助類),並且這些對象的值數組列表在表中被渲染。我的控制器,JSP頁面,並幫助類有如下

控制器

public class HomeController { 

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class); 

    /** 
    * Simply selects the home view to render by returning its name. 
    */ 
    @RequestMapping(value = "/", method = RequestMethod.GET) 
     public String home(Model model) { 
      logger.info("Welcome home! the client locale is "); 




      ArrayList<TrendSign> ts=new ArrayList<TrendSign>(); 
      for(int i=0;i<5;i++) 
      { 
       TrendSignDAO actor = new TrendSignDAO(); 
       actor.setPhrase("phrase"+i); 
       actor.setHitCount(i); 
       actor.setWordCount(i); 
       actor.setCharCount(i); 
       ts.add(actor); 
      } 

      model.addAttribute("ts", ts); 

      return "home"; 
    } 

} 

JSP頁面如下:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ page session="false" %> 
    <html> 
    <head> 
     <title>Home</title> 
     </head> 
    <body> 
     <table border=1> 
      <thead> 
       <tr> 
        <th>Phrase</th> 
        <th>hit count</th> 
        <th>wordcount</th> 
        <th>char count</th> 
       </tr> 
      </thead> 
      <tbody> 
       <c:forEach var="row" items="${ts}"> 
        <tr class="odd gradeX"> 
         <td><c:out value="${row.getPhrase()}"/></td> 
         <td><c:out value="${row.getHitCount()}"/></td> 
         <td><c:out value="${row.getWordCount()}"/></td> 
         <td><c:out value="${row.getCharCount()}"/></td> 
        </tr> 
       </c:forEach> 
     </tbody> 
    </table> 
    </body> 
</html> 

幫助類

public class TrendSign { 

private String phrase; 
private int hitCount; 
private int wordCount; 
private int charCount; 

public void setPhrase(String phrase) 
{ 
    this.phrase = phrase; 
} 
public String getPhrase() 
{ 
    return (this.phrase); 
} 
public void setHitCount(int hitCount) 
{ 
    this.hitCount = hitCount; 
} 
public int getHitCount() 
{ 
    return (this.hitCount); 
} 
public void setWordCount(int wordCount) 
{ 
    this.wordCount = wordCount; 
} 
public int getWordCount() 
{ 
    return (this.wordCount); 
} 
public void setCharCount(int charCount) 
{ 
    this.charCount = charCount; 
} 
public int getCharCount() 
{ 
    return (this.charCount); 
} 


public TrendSignDAO() { 
    // TODO Auto-generated constructor stub 
    this.phrase = "Phrase"; 
    this.hitCount = 5; 
    this.wordCount = 1; 
    this.charCount = 1; 
} 

} 

這工作正常我的本地主機(java 6 Tomcat 6)但是當我部署到jelastic(java 6 Tomcat 6)時,得到錯誤W EB-INF/views/home.jsp(26,8)當沒有指定默認名稱空間時,函數getPhrase必須與前綴一起使用。訪問jelastic網絡應用的網址是http://lovedmusic.jelastic.servint.net/。任何人都可以幫助我如何調試?

+0

DAO看起來像DTO或VO或Pojo,而不是DAO(數據訪問層)。 – 2013-04-23 05:30:01

回答

2

你的DAO並不完全像一個DAO,但儘管如此,使用JSP-EL,你應該能夠訪問你的干將沒有方法的語法。只需使用屬性名稱:

<td><c:out value="${row.phrase}"/></td>  
<td><c:out value="${row.hitCount}"/></td> 
<td><c:out value="${row.wordCount}"/></td> 
<td><c:out value="${row.charCount}"/></td> 
+0

嗨,是啊幫助類不是DAO,我剛纔的名字。將row.getPhrase()更改爲row.phrase適用於我,並且我能夠無錯地訪問該Web應用程序。謝謝! – 2013-04-23 05:55:50

相關問題