使用struts 2在jsp中显示blob图像

时间:2012-07-29 21:47:58

标签: jsp struts2

您好我按照我在这里看到的一个例子,但结果不好,我将其作为ShowImageAction

public static void execute() throws RemoteException {  

HttpServletResponse response = ServletActionContext.getResponse();  
response.reset();  
response.setContentType("multipart/form-data");   
session = ActionContext.getContext().getSession(); 
PublicApiService_PortType puerto=(PublicApiService_PortType) session.get("puerto"); 
((BasicHttpBinding_PublicApiServiceStub)puerto).setMaintainSession(true); 

MessageContext ctx=(MessageContext) session.get("contexto"); 
PapiUserInfo[] users; 

users = puerto.getUsers(); 
Long accountID=users[0].getID(); 
PapiAccountInfo info=puerto.getAccountInfo(accountID); 
itemImage=info.getWhiteLabelingLogo(); 
System.out.println(itemImage); 
OutputStream out; 

try { 
    out = response.getOutputStream(); 
    out.write(itemImage);  
       out.flush();  
       out.close(); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 




} 

getWhiteLabelingLogo();将blob返回到byte[]然后在我的jsp上我有这个:

<img src="<s:url value="ShowImageAction" />" border="0" width="100" height="100">  

为什么它不起作用?这样对吗?。非常感谢

1 个答案:

答案 0 :(得分:0)

您需要为Dave提到的流结果类型实现的基础知识:

strusts.xml:

<action name="yourImageStreamAction">
    <result name="success" type="stream">
        <param name="inputName">inputStream</param>
    </result>
</action>

动作:

private InputStream inputStream = null;

public String execute() {
   //set inputStream from itemImage.  
   //I don't know what itemImage is, so I'll leave that to you
   return SUCCESS;
}

public InputStream getInputStream() {
   return this.inputStream;
}