想写一个自定义标签,实现,输入表的名字,输入ID 查出 名称来。 为什么实现这个功能,因为页面上显示名称的时候,必须要在数据库码表通过ID 去翻译一下。这样很麻烦。
我想用表标签的形式,定义两个属性,一个是表名字,一个是ID
现在在标签类里面引入的 DAO 总是报错:j
avax.naming.NameNotFoundException: Name com.jiashi.epg.selfTag.MySelfTag is not bound in this Context
[code="java"]
@Resource
JdbcDao jdbcDao;----问题出现在这里
private String code;
private String tablebyadd;
public void setCode(String code) {
this.code = code;
}
public void setTablebyadd(String tablebyadd) {
this.tablebyadd = tablebyadd;
}
@Override
public int doEndTag() throws JspException {
String strNm = "";
JspWriter out = pageContext.getOut();
try {
// if (StringUtils.isNotBlank(code)
// && StringUtils.isNotBlank(tablebyadd)) {
// String sql = "select name from " + tablebyadd
// + " t where t.id = '" + code + "'";
// List list = dao.query(sql, null);
// if (list.size() > 0) {
// strNm = list.get(0);
// out.write("
" + strNm + "
");// }
// }
out.write("
" + jdbcDao + tablebyadd + "
");} catch (Exception e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
[/code]