java - 为什么 jasper 得到一个字符串而不是一个类对象?
问题描述
我正在尝试通过属性将 bean 对象传递给自定义标签。豆:
public class Statistic implements Serializable {
private float average;
// ...
public Statistic() {
this.average = 0;
// ...
}
public float getAverage() {
return average;
}
public void setAverage(float average) {
this.average = average;
}
// ...
}
统计.tld
<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>
统计标签
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;
}
}
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>
如何将统计对象传递给 JSP:
request.setAttribute("statisticData", statistic);
getServletContext().getRequestDispatcher("/result.jsp").forward(request, response);
加载 result.jsp 时,出现错误:org.apache.jasper.JasperException: Unable to convert string "${statisticData}" to class "classes.Statistic" for attribute "data": Property Editor not registered with the PropertyEditorManager
. 那么为什么 jasper 得到一个字符串而不是一个类对象呢?没有引号我得到一个错误org.apache.jasper.JasperException: /result.jsp (line: 9, column: 21) quote symbol expected
。
解决方案
推荐阅读
- rust - 为什么 Rust 允许升级/降级可变性?
- sql - 如何在 redshift 的子查询中使用外部表中的值?
- python - 如何在模板中添加条件以检测超级用户与帖子作者相同
- python - Kivy 按钮类不执行后续命令
- python - Python FlaskKafka - 总线线程上的异常会杀死线程,我必须重新启动应用程序
- ffmpeg - ffmpeg 平铺图像来自视频总图像计数
- java - 字符串中整数的总和?
- python - 多重继承python问题
- json - 使用JsonSlurper遍历列表时如何提取json内容而不丢失引号
- javascript - Angular 获取浏览器名称和版本