JSP自定义标签:无法转换[B @ 33818e类型类[B到类[Ljava.lang.Byte

时间:2016-10-11 09:13:08

标签: java spring spring-mvc jstl taglib

我在使用WebLogic服务器的Spring Framework MVC应用程序中工作。我正在使用jstl 1.2。我有一个由我创建的自定义taglib

我已创建此标记:

public class DisplayImageTag extends SimpleTagSupport {

    private Collection<Image> images;
    private byte[] logo;
    private String action;

    @Override
    public void doTag() throws JspException, IOException {

        PageContext pc = (PageContext)getJspContext();
        JspWriter out = getJspContext().getOut();
        String fullPath = TDKUtils.getTDKPath(pc);

        StringBuffer sb = new StringBuffer(" ");
        if(action != null) {
            action = action.trim();
        }

        if (this.images!=null) {            
            for (Image img : this.images) {

                Long id = img.getId()!=null ? img.getId() : img.getTempId();

                sb.append("<img src='" + fullPath + "/displayImage?" + DisplayImageServlet.IMG_ID + "=" + id+"&resize=true' align='bottom' >&nbsp;");

                // create and show delete button if action arg passed
                if (action != null && !action.trim().equals("")) {
                    sb.append("<a href='" + this.action + "?name=image&id=" + img.getTempId() + "&action=delete'>");
                    sb.append("<img src='" + fullPath + "/images/delete.png' ");
                    sb.append("alt='Delete picture' class='whattodo' style='border-width: 0pt;' align='bottom' /></a>");
                }
            }
        }
        out.print(sb);
    }

    public void setImages(Collection<Image> images) {
        this.images = images;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public void setLogo(byte[] logo) {
        this.logo = logo;
    }
}

和这个bean

public class Club implements java.io.Serializable {


    private byte[] logo;
    ..
}

和我的JSP

<tdk:displayImage logo="${club.logo}"  />

但我收到了这个错误:

javax.el.ELException: java.lang.IllegalArgumentException: Cannot convert [B@33818e of type class [B to class [Ljava.lang.Byte;

1 个答案:

答案 0 :(得分:0)

很可能类转换不适用于基本类型,Byte []应该可以工作。