在Custom JSP标记中传递Java对象值

我正在尝试从自定义jsp标记传递一个java变量(我在这里使用struts2来从java类中获取变量)。 这是我得到的错误。

javax.servlet.ServletException: /pages/editBidForm.jsp(51,8) According to TLD or attribute directive in tag file, attribute parentId does not accept any expressions org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) .... 

这是我的jsp页面(部分)

   ... ... 
<custom:zorancustomtag parentType = "BIDFORM" parentId = "" />

我无法正确传递parentId参数。 我能够正确传递parentType参数,因为它只涉及传递字符串

这是taglib文件。

    1.0 1.1 custom  zorancustomtag com.zoran.action.CustomizedTag JSP Tag having a body and attributes  name false false   parentType true true   parentId true false    

和自定义标记的java类。

 public class CustomizedTag implements Tag { private PageContext pageContext; private Tag parent; private String name; private int parentId; private String parentType; List list = null; public String getName() { return name; } public void setName(String name) { this.name = name; } /* public CustomizedTag() { super(); } */ public int doStartTag() throws JspException { Session session = SessionUtil.getSession(); session.beginTransaction(); try { JspWriter out = pageContext.getOut(); String parId = getParentId()+""; // out.println(getParent()+" "); String quer = "from ContentBase cb where cb.parentType=? AND cb.parentId=? ";//+parId; Query query = session.createQuery(quer); query.setParameter(0, getParentType()); query.setParameter(1, getParentId()); list = query.list(); ContentBase cb = new ContentBase(); if (null != list && !list.isEmpty()) { cb = (ContentBase) list.get(0); } // pageContext.getOut().print("Sri "+getName()); out.println(cb.getDescription()); } catch (IOException ioe) { throw new JspException("Error:"+ioe.getMessage()); } return SKIP_BODY; } public int doEndTag() throws JspException { return SKIP_PAGE; } public void release() { } public void setPageContext(PageContext pageContext) { this.pageContext = pageContext; } public void setParent(Tag parent) { this.parent = parent; } public Tag getParent() { return parent; } public int getParentId() { return parentId; } public void setParentId(int parentId) { this.parentId = parentId; } public String getParentType() { return parentType; } public void setParentType(String parentType) { this.parentType = parentType; } } 

谁能告诉我如何通过自定义jsp标签传递java变量。

谢谢,Aditya

您的TLD中的元素应为并且需要设置为true

   parentId true true  

这允许运行时表达式作为属性值提供。 关于JSP设计团队中谁认为允许将其设置为false是一个好主意,我仍然感到困惑。

尝试将parentId值包装在$ {}中

 }" />