Help!自定义标签属性传值的问题!!!
我的标签类如下:
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; } }
<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>
<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>
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; }}