I would to know why I don’t get anything with this. I have a function who return a byte array from SQL Server 2008 but I don’t get anything, why? .getWhiteLabelingLogo() is a function which returns a byte[] with the image which I want to show at the jsp page. I access to this
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.rmi.RemoteException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.axis.MessageContext;
import org.apache.struts2.ServletActionContext;
import org.datacontract.schemas._2004._07.CCIS_Web_Services_PublicApi.PapiAccountInfo;
import org.datacontract.schemas._2004._07.CCIS_Web_Services_PublicApi.PapiUserInfo;
import Services.Web.CCIS.BasicHttpBinding_PublicApiServiceStub;
import Services.Web.CCIS.PublicApiService_PortType;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class ShowImageAction extends ActionSupport{
Map session;
private byte[] itemImage;
private InputStream str = null;
public String execute() throws RemoteException {
System.out.println("Estoy aquí");
HttpServletResponse response = ServletActionContext.getResponse();
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();
str=new ByteArrayInputStream(itemImage);
return SUCCESS;
}
public void setItemImage(byte[] itemImage) {
this.itemImage = itemImage;
}
public InputStream getStr() {
return str;
}
public void setStr(InputStream str) {
this.str = str;
}
public byte[] getItemImage() {
return itemImage;
}
}
at index.jsp I have this:
<img src="<s:url value="ShowImageAction" />" border="0" width="100" height="100">
And in struts.xml I have this:
<action name="ShowImageAction">
<result name="success" type="stream">
<param name="inputName">str</param>
<param name="contentType">image/jpeg</param>
</result>
</action>
What I’m doing bad because I haven’t anything. Thanks so much
Well, for starters, you don’t have an action method at all. You do have a method named
execute, but it is static and returns void. Action methods are non-static and return a String, which maps to a result in the struts.xml.Additionally, after you set the content type on the response, you never send any data.
There are other problems with this action as well, such as the use of mutable static fields on the action, which is not thread-safe.
Here are some steps to take:
executemethod to be non-static and return a Stringreturn SUCCESS;line at the end of the methodExample:
Then, if it is still not working for you, revise your question appropriately.