Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用struts 2在jsp中显示blob图像_Jsp_Struts2 - Fatal编程技术网

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

使用struts 2在jsp中显示blob图像,jsp,struts2,Jsp,Struts2,您好,我遵循我在这里看到的一个示例,但结果不好,我将其作为showmageaction: public static void execute() throws RemoteException { HttpServletResponse response = ServletActionContext.getResponse(); response.reset(); response.setContentType("multipart/form-data"); session

您好,我遵循我在这里看到的一个示例,但结果不好,我将其作为
showmageaction

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">  
“border=“0”width=“100”height=“100”>

为什么它不起作用?是否正确?非常感谢Dave提到的流结果类型需要实现的基本知识:

strusts.xml:

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

multipart/form data
不是有效的图像mime类型。根据图像的类型,您可能应该使用
image/jpeg
image/png
。非常感谢您的回答。其余代码都很好?。Thanks@zoit也许吧,但是为什么不直接使用
“流呢“
result type?where?,你能给我介绍一下吗?。你应该试试谷歌。它工作得很好!尝试类似“struts2 stream result”的内容。您好,我一直在尝试按照您说的做,但什么都没有我有这个:showmageaction.java我有这个:
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;
}