0

我在这里问了类似的问题 当未指定默认命名空间时,函数“”必须与前缀一起使用。但我的背景不同。

我有一个 Spring Web 应用程序,其中包含一个 jsp,它从控制器获取创建的对象的数组列表(使用帮助类),并且这些对象值呈现在一个表中。我的Controller、Jsp页面、Helping类如下

控制器

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)时,出现错误 WEB-INF/views/home.jsp(26,8) 函数 getPhrase 必须与未指定默认命名空间时的前缀。在 jelastic 上访问网络应用程序的 URL 是http://lovedmusic.jelastic.servint.net/。谁能帮我调试一下?

4

1 回答 1

2

您的 DAO 看起来不太像 DAO,但尽管如此,使用 JSP-EL,您应该能够在没有方法语法的情况下访问您的 getter。只需使用属性名称:

<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>
于 2013-04-23T05:27:52.547 回答