gpt4 book ai didi

java - Wicket 6 NonCachingImage 未在 HTML 中显示

转载 作者:行者123 更新时间:2023-12-01 11:14:26 25 4
gpt4 key购买 nike

我真的被这个问题难住了:这是我创建动态图像的方法。

 private Image createImage(final String id, final byte[] imageData){
NonCachingImage chartImage=new NonCachingImage(id) {
private static final long serialVersionUID = 1L;

@Override
protected IResource getImageResource() {
return new DynamicImageResource(){
private static final long serialVersionUID=1L;
@Override
protected byte[] getImageData(Attributes attributes) {
String myImageStr = new StringBuffer(
WicketApplication.TOMCAT_IMAGE_DOC_BASE).
append("13835.jpg").toString();
File file = new File(myImageStr);
try {
return Files.readBytes(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
};
}

};
chartImage.setOutputMarkupId(true);
chartImage.setOutputMarkupPlaceholderTag(true);
return chartImage;
}

这是我使用它的地方

Image img = createImage("orig_photo", uploadedFile.getBytes());pnlForm.addOrReplace(img);

我的 HTML

<img width="100" height="133" title="Photo" wicket:id="orig_photo"/>

出现此错误:

在 Javascript Inspect Element 中出现此错误:获取https://localhost/admin/admnwtxtprofile?5-IResourceListener-wProfileTxtPnl-wProfileTxtForm-orig_photo&antiCache=1439492929071 404(未找到)

最佳答案

您已将 imageData 提供给 createImage 但未在方法内部使用。我假设您上传的文件来自某个文件夹?可能是温度?

下面的代码与您的代码类似,工作正常,显示图像。

public class WicketApplication extends WebApplication {

public static final String LOCAL_IMAGE_BASE = "c:\\myimages\\";
...
}

public class TestDynaImageFilePage extends WebPage {

public TestDynaImageFilePage(PageParameters parameters) {
super(parameters);
Form<Void> form = new Form<Void>("imageForm");
form.setOutputMarkupId(true);

add(form);

addFormComponents(form);
}

private void addFormComponents(Form<Void> form) {
Path path = Paths.get("src/main/webapp/images/help.png");
try {
byte[] data = java.nio.file.Files.readAllBytes(path);
Image img = createImage("orig_photo", data);
form.addOrReplace(img);
} catch (IOException e) {
e.printStackTrace();
}
}

private Image createImage(final String id, final byte[] imageData) {
NonCachingImage chartImage = new NonCachingImage(id) {
private static final long serialVersionUID = 1L;

@Override
protected IResource getImageResource() {
return new DynamicImageResource() {
private static final long serialVersionUID = 1L;

@Override
protected byte[] getImageData(Attributes attributes) {
String myImageStr = new StringBuffer(
WicketApplication.LOCAL_IMAGE_BASE).
append("help.png").toString();
File file = new File(myImageStr);
try {
return Files.readBytes(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
};
}

};
chartImage.setOutputMarkupId(true);
chartImage.setOutputMarkupPlaceholderTag(true);
return chartImage;
}
}

HTML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:wicket>
<head>

</head>
<body>
<form wicket:id="imageForm">
<img width="100" height="133" title="Photo" wicket:id="orig_photo"/>
</form>
</body>
</html>

关于java - Wicket 6 NonCachingImage 未在 HTML 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31996827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com