首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

Help!自定义标签属性传值的有关问题!

2012-01-23 
Help!自定义标签属性传值的问题!!!我的标签类如下:Java codepackage org.tag.imageimport java.io.IOExce

Help!自定义标签属性传值的问题!!!
我的标签类如下:

Java code
package org.tag.image;import java.io.IOException;import javax.servlet.jsp.JspContext;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.tagext.JspFragment;import javax.servlet.jsp.tagext.SimpleTagSupport;public class ImageTag extends SimpleTagSupport {        private JspFragment body;    private Image image;        public void setImage(Image image) {        this.image = image;    }    public void doTag() throws JspException, IOException {        JspContext jspCtx = getJspContext();        JspWriter out = jspCtx.getOut();        out.println("<img src="+image.getPath()+"/>");        body.invoke(null);    }    protected void getJspBody(JspFragment jspBody) {        this.body = jspBody;    }    }

tld如下:
XML code
  <tag>      <name>logo</name>      <tag-class>org.tag.image.ImageTag</tag-class>      <body-content>tagdependent</body-content>          <attribute>              <name>image</name>                        <required>true</required>              <rtexprvalue>true</rtexprvalue>          </attribute>  </tag>


JSP页面:
HTML code
  <body>   <jsp:useBean id="image" scope="page" class="org.tag.image.Image"></jsp:useBean>     <%image.setName("123");        image.setPath("./style/image/bg0.jsp");%>    <div id = "container">        <div id = "header">            <div id = "logo">                <my:logo image="image"></my:logo>            </div>        </div>    </div>  </body>

运行后抛出异常:ServletException raised in SimpleFilter Unable to convert string "image" to class "org.tag.image.Image" for attribute "image": Property Editor not registered with the PropertyEditorManager
请问这个问题怎么解决,我就是想把一个image对象传入标签,让它在界面上显示。
我的image类:
Java code
public class Image {    private String name;    private String path;        public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getPath() {        return path;    }    public void setPath(String path) {        this.path = path;    }}


[解决办法]
<my:logo image="<%=image%>">

热点排行