Question

I have similar problem asked here The function " " must be used with a prefix when a default namespace is not specified . But my context is different.

I have Spring web app which contains a jsp that gets arraylist of Objects created (using helping class) from controller and these object values are rendered in a table. My Controller, Jsp page, and Helping class are as follows

Controller

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 Page is as follows:

<%@ 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>

Helping class

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;
}

}

This working fine in my local host (java 6 Tomcat 6) But when I deployed to jelastic(java 6 Tomcat 6), getting the error WEB-INF/views/home.jsp(26,8) The function getPhrase must be used with a prefix when a default namespace is not specified. The url to access the web app at jelastic is http://lovedmusic.jelastic.servint.net/. Can anyone help me how to debug this?

Was it helpful?

Solution

Your DAO doesn't quite look like a DAO, but nevertheless, using JSP-EL, you should be able to access your getters without the method syntax. Just use the property name:

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top