1

I have some problems to display image from database.

Article.class

@Entity
@Table(name = "cmr_article", indexes = { @Index(columnList = "name",    unique = true) })
public class Article {

public static final int NAME_MAX = 50;
public static final int DESCRIPTION_MAX = 100;
public static final int FULL_MAX = 500;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@Column(nullable = false, length = NAME_MAX)
private String name;

@Column(nullable = false, length = DESCRIPTION_MAX)
private String description;

@Lob
@Column(nullable = false, length = FULL_MAX)
private String full;

@Column(nullable = false)
private String date;

@Column(nullable = false)
private byte[] data;

@ManyToOne
private User user;

Article save:

@Transactional(propagation=Propagation.REQUIRED, readOnly=false)
public void articleSave2(long userId, ArticleForm articleForm) {
    User user = userRepository.findOne(userId); 
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    Date date = new Date();
    Article article = new Article();
    article.setName(articleForm.getName());
    article.setDescription(articleForm.getDescription());
    article.setDate(dateFormat.format(date));
    article.setFull(articleForm.getFull());
    article.setData(articleForm.getData()); 
    article.setUser(user);
    articleRepository.save(article);
}

jps file:

<img src='<c:out value="${article.data}"></c:out>' />

Problem is that the image in JSP file is not display, it display code: [B@6acdfc86 . In MYSQL I see that i save image. How can i change code to see image in my jsp?

jonathan.cone
  • 6,592
  • 2
  • 30
  • 30

1 Answers1

0

There's no way to do what you're trying to with a raw byte array and JSP EL. You'll either need to embed the image as base 64 data as described here or you'll need to save the image to disk some place and supply a URL to access it in the src attribute.

Community
  • 1
  • 1
jonathan.cone
  • 6,592
  • 2
  • 30
  • 30