Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: None  |  size: 1.45 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Displaying a blob image in jsp with struts 2
  2. public static void execute() throws RemoteException {  
  3.  
  4. HttpServletResponse response = ServletActionContext.getResponse();  
  5. response.reset();  
  6. response.setContentType("multipart/form-data");  
  7. session = ActionContext.getContext().getSession();
  8. PublicApiService_PortType puerto=(PublicApiService_PortType) session.get("puerto");
  9. ((BasicHttpBinding_PublicApiServiceStub)puerto).setMaintainSession(true);
  10.  
  11. MessageContext ctx=(MessageContext) session.get("contexto");
  12. PapiUserInfo[] users;
  13.  
  14. users = puerto.getUsers();
  15. Long accountID=users[0].getID();
  16. PapiAccountInfo info=puerto.getAccountInfo(accountID);
  17. itemImage=info.getWhiteLabelingLogo();
  18. System.out.println(itemImage);
  19. OutputStream out;
  20.  
  21. try {
  22.     out = response.getOutputStream();
  23.     out.write(itemImage);  
  24.        out.flush();  
  25.        out.close();
  26. } catch (IOException e) {
  27.     // TODO Auto-generated catch block
  28.     e.printStackTrace();
  29. }
  30.  
  31.  
  32.  
  33.  
  34. }
  35.        
  36. <img src="<s:url value="ShowImageAction" />" border="0" width="100" height="100">
  37.        
  38. <action name="yourImageStreamAction">
  39.     <result name="success" type="stream">
  40.         <param name="inputName">inputStream</param>
  41.     </result>
  42. </action>
  43.        
  44. private InputStream inputStream = null;
  45.  
  46. public String execute() {
  47.    //set inputStream from itemImage.  
  48.    //I don't know what itemImage is, so I'll leave that to you
  49.    return SUCCESS;
  50. }
  51.  
  52. public InputStream getInputStream() {
  53.    return this.inputStream;
  54. }