Java 为什么jasper得到的是字符串而不是类对象?
我试图通过属性将bean对象传递给自定义标记。 豆子: statistic.tldJava 为什么jasper得到的是字符串而不是类对象?,java,jsp,Java,Jsp,我试图通过属性将bean对象传递给自定义标记。 豆子: statistic.tld <taglib> <tlib-version>1.0</tlib-version> <jsp-version>2.0</jsp-version> <short-name>Statistic TLD</short-name> <tag> <name>Statisti
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>Statistic TLD</short-name>
<tag>
<name>Statistic</name>
<tag-class>tags.StatisticTag</tag-class>
<body-content></body-content>
<attribute>
<name>data</name>
<required>true</required>
<type>classes.Statistic</type>
<fragment>false</fragment>
</attribute>
</tag>
</taglib>
JSP文件
<%@ taglib prefix = "st" uri = "WEB-INF/statistic.tld"%>
<jsp:useBean id="statisticData" class="classes.Statistic" scope="page" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index</title>
</head>
<body>
<st:Statistic data="${statisticData}" />
</body>
</html>
加载result.jsp时,出现错误:
org.apache.jasper.jaspereException:无法将字符串“${statisticData}”转换为属性“data”的类“classes.Statistic”:属性编辑器未向PropertyEditorManager注册
。那么为什么jasper得到的是字符串而不是类对象呢?如果没有引号,我会得到一个错误org.apache.jasper.JasperException:/result.jsp(第9行,第21列)预期的引号符号
Hi,检查答案可能有帮助。@Swati它对我没有帮助:(Hi,检查答案可能有帮助。@Swati它对我没有帮助:(
public class StatisticTag extends SimpleTagSupport {
private Statistic statistic;
// ...
public void doTag()
throws JspException, IOException {
// ...
}
public Statistic getData() {
return statistic;
}
public void setData(Statistic value) {
this.statistic = statistic;
}
}
<%@ taglib prefix = "st" uri = "WEB-INF/statistic.tld"%>
<jsp:useBean id="statisticData" class="classes.Statistic" scope="page" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index</title>
</head>
<body>
<st:Statistic data="${statisticData}" />
</body>
</html>
request.setAttribute("statisticData", statistic);
getServletContext().getRequestDispatcher("/result.jsp").forward(request, response);