我正在调用一个 SOAP webservice ,它返回一个 Image as SOAP Attachment ,即
<Image>
<xop:Include href="cid:10ee9.." >
</Image>
我会在附件中得到这个图像,即
AttachmentPart attachment = (AttachmentPart)iterator.next();
附件是否需要转换,还是会存储在数据库中?
答案 0 :(得分:0)
服务响应可能包含图片base64或信封外的附件。解码base64的示例:
public static BufferedImage decodeToImage(String imageString) {
BufferedImage image = null;
byte[] imageByte;
try {
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imageString);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
return image;
}
JAVA已经有一个用于处理带附件的SOAP的API。
SOAPMessage response = connection.call(requestMessage, serviceURL);
Iterator attachmentsIterator = response.getAttachments();
while (attachmentsIterator.hasNext()) {
AttachmentPart attachment = (AttachmentPart) attachmentsIterator.next();
//do something with attachment
}
只要您的图像存储在服务器可以提供的文件夹中,您只需要在JSP页面中添加元素并使其'src'属性保存图像的路径。
例如,假设您将图像存储在可由服务器提供的名为“images”的文件夹中。您必须在JSP页面中插入一个元素,例如:
<img src="http://localhost:8080/images/image_name.jpg" /img>
答案 1 :(得分:0)
另一种方法
你可以这样做
try{
String fileName = request.getParameter("image");
FileInputStream fis = new FileInputStream(new File("d:\\"+fileName));
BufferedInputStream bis = new BufferedInputStream(fis);
response.setContentType(contentType);
BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream());
for (int data; (data = bis.read()) > -1;) {
output.write(data);
}
}
catch(IOException e){
}finally{
// close the streams
}
要传递图像路径,您可以像这样使用src
<img src="<%=request.getParameter("image")%>">