我在这里遇到类似的问题The function " " must be used with a prefix when a default namespace is not specified。但我的背景不同。
我有一个Spring网络应用程序,其中包含一个jsp,它从控制器获取对象的arraylist(使用帮助类),这些对象值在表中呈现。我的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的Web应用程序的网址是http://lovedmusic.jelastic.servint.net/。任何人都可以帮我如何调试这个?
答案 0 :(得分: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>