struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Siena, Christina \(.\)" <csi...@ford.com>
Subject RE: Displaying image data from the database
Date Fri, 18 Jun 2004 12:44:12 GMT
Hi,

I'm not using Tomcat. I'm using IBM WebSphere Application Server, Release 4.0.6 but I'll try
 <html:img> </html:img>.

Thanks,

Christina

-----Original Message-----
From: Amleto Di Salle [mailto:disalle@di.univaq.it] 
Sent: Friday, June 18, 2004 5:27 AM
To: 'Struts Users Mailing List'
Subject: R: Displaying image data from the database


Hi,
Which Tomcat version are you using?
The problem seems to be a Tomcat problem with the body content and the Pooling of the Tag.
Anyway in the Tomcat 5.0.25 this bug is solved.

Try to do the following: 
In the <html:img> tags, don't use the empty element tag (i.e. with / at the end of the
tag) but use <html:img> </html:img> (you have to put the end-tag put in an other
line, i.e use return line).

This is because Tomcat (i.e. Jasper) "traslate" in different ways between empty-tag, and a
tag with start and end element. Using the start and end element (with CR line!), the bug doesn't
appear.


BR
/Amleto


-----Messaggio originale-----
Da: Siena, Christina (.) [mailto:csiena@ford.com] 
Inviato: venerdì 18 giugno 2004 1.29
A: Struts Users Mailing List
Oggetto: RE: Displaying image data from the database


Sorry that my last email was badly formatted so I am reposting it again. Hope its more readable.

-----Original Message-----
From: Siena, Christina (.) 
Sent: Thursday, June 17, 2004 7:15 PM
To: user@struts.apache.org
Subject: Displaying image data from the database


I've been using a solution that I found by searching the struts user archive to display image
data from the database.

I've developed a page that displays at most two images on one page (one is referred as the
"global" image and the other the "local" image in the code shown below).

Most of the time the correct images are displayed, however, sometimes the same image is displayed
for both "global" and "local" but the images stored are actually different. There is an inconsistency.
Re-displaying the page sometimes shows the same image and sometimes different images. Any
ideas?


Here is parts of interface
WebDefs:****************************************************************

	public static final String PARAM_IS_GLOBAL_IMAGE = "isGlobalImage";
	public static final String PARAM_GLOBAL_ID = "globalId";
	public static final String PARAM_LOCAL_ID = "localId";


Here is the main action
class:******************************************************************

public class LoadCampaignImageAction extends LoadImageAction implements WebDefs {

    public ActionForward executeAuthorized(ActionMapping mapping,
	ActionForm form,
 	HttpServletRequest request,
	HttpServletResponse response) throws Exception {

    	trace(" -- entered " + this.getClass().getName() + ".executeAuthorized(mapping, form,
request, response)");
    	
    	String isGlobalImageParam = request.getParameter(PARAM_IS_GLOBAL_IMAGE);
    	String globalIdParam = request.getParameter(PARAM_GLOBAL_ID);
    	String localIdParam = request.getParameter(PARAM_LOCAL_ID);

	ConsumerCampaignImageDTO imageDTO = null;

    	try {
    		ConsumerCampaignService ccsService = new ConsumerCampaignService(super.getIsisUserContext(request));

    		if (globalIdParam != null) {

			ConsumerCampaignGlobalPKDTO globalCampaignPK =
new ConsumerCampaignGlobalPKDTO();
			globalCampaignPK.setGlobalCampaignId(new
Integer(globalIdParam));
	
globalCampaignPK.restoreFromVersionedString(globalCampaignPK.toVersioned
String());
			ConsumerCampaignGlobalDTO globalDTO = ccsService.getGlobalCampaign(globalCampaignPK);

			if (isGlobalImageParam.equals("true")) {
				imageDTO = globalDTO.getGlobalImage();
			} else {
				imageDTO =
globalDTO.getMasterLocalRecord().getImage();
			}
    		} else if (localIdParam != null &&
isGlobalImageParam.equals("false")) {

			ConsumerCampaignInfoPKDTO localCampaignPK = new ConsumerCampaignInfoPKDTO();
			localCampaignPK.setCampaignId(new
Integer(localIdParam));
	
localCampaignPK.restoreFromVersionedString(localCampaignPK.toVersionedSt
ring());
			ConsumerCampaignLocalDTO localDTO = ccsService.getLocalCampagin(localCampaignPK);
			imageDTO = localDTO.getImage();
    		}
	} catch (IsisObjectNotFoundException e) {
	    	Object[] params = null;
    		if (globalIdParam != null) {
			warning(this.getClass().getName() + " IsisObjectNotFoundException occurred");
		    	params = new Object[] {
getResources(request).getMessage("message.type.campaignGlobal") , globalIdParam ;
    		} else if (localIdParam != null &&
isGlobalImageParam.equals("false")) {
			warning(this.getClass().getName() + " IsisObjectNotFoundException occurred");
		    	params = new Object[] {
getResources(request).getMessage("message.type.campaignLocal") , localIdParam };
    		}
	    	ActionErrors actionErrors = new ActionErrors();
		handleObjectNotFoundException(request, actionErrors, "error.staleDataArg2", params);
		saveErrors(request, actionErrors);
	    	return
(mapping.findForward(FORWARD_CAMPAIGN_NOT_FOUND));
    	}
    	
    	if (imageDTO != null) {
	    	super.setImage(imageDTO.getImage());
	    	super.setImageType(imageDTO.getImageType());
    	}

      return (super.executeAuthorized(mapping, form, request, response));
    }
}


Here is the abstract superclass that serves the
images:**********************************************

public abstract class LoadImageAction extends IsisBaseAction {

	private byte[] image = null;

	private String imageType = null;

	public ActionForward executeAuthorized(ActionMapping mapping,
		ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{

	    	trace(" -- entered " + this.getClass().getName() + ".executeAuthorized(mapping, form,
request, response)");
    	
		try {
			final String prefix = "image";
			final String suffix = null;
			File file = File.createTempFile(prefix, suffix);
			FileOutputStream fileOutputStream = new FileOutputStream(file);
			fileOutputStream.write(getImage());
			fileOutputStream.close();
			response.setContentType(getImageType());
			response.setHeader("Content-Disposition",
"filename=" + file.getName());
			response.setHeader("Cache-Control", "no-cache");
			response.setContentLength((int)file.length());
			OutputStream outputStream =
response.getOutputStream();
			FileInputStream fileInputStream = new
FileInputStream(file);
			byte[] buffer = new byte[(int)file.length()];
			fileInputStream.read(buffer);
			outputStream.write(buffer);
			outputStream.flush();
			outputStream.close();
			fileInputStream.close();
			file.delete();
			file.deleteOnExit();
		} catch (IOException ioe) {
		    	trace(this.getClass().getName() + "==>> " + ioe.toString());
		}

        return null;
    }

    /**
     * Returns the image.
     * @return byte[]
     */
    private byte[] getImage() {
        return image;
    }

    /**
     * Sets the image.
     * @param image The image to set
     */
    protected void setImage(byte[] image) {
        this.image = image;
    }

    /**
     * Returns the imageType.
     * @return String
     */
    private String getImageType() {
        return imageType;
    }

    /**
     * Sets the imageType.
     * @param imageType The imageType to set
     */
    protected void setImageType(String imageType) {
        this.imageType = imageType;
    }
}


Here are snippets of the
JSP:********************************************************************

<%-- DISPLAY GLOBAL IMAGE --%>

<tr>
	<td align="left">
		<bean:message key="previewLocalCampaign.imageGlobal"
bundle="<%=IConstant.PAGE_RESOURCES_KEY%>"/>
	</td>
	<td align="left">
		<bean:define id="globalIdValue" name="previewLocalCampaignForm" property="globalId" type="java.lang.String"/>
		<bean:define id="imageWidthGlobalValue" name="previewLocalCampaignForm" property="imageWidthGlobal"
type="java.lang.String"/>
		<bean:define id="imageHeightGlobalValue" name="previewLocalCampaignForm" property="imageHeightGlobal"
type="java.lang.String"/>
		<%
			map = new HashMap();
			map.put("globalId", globalIdValue);
			map.put("isGlobalImage","true");
			pageContext.setAttribute("map", map, PageContext.PAGE_SCOPE);
		%>
		<html:img styleId="imagePreviewGlobal" page="/loadCampaignImage.do" name="map" 
			width="<%=imageWidthGlobalValue%>"
height="<%=imageHeightGlobalValue%>"/>
	</td>
</tr>

<%-- DISPLAY LOCAL IMAGE --%>

<tr>
	<td align="left">
		<bean:message key="previewLocalCampaign.imageLocal"
bundle="<%=IConstant.PAGE_RESOURCES_KEY%>"/>
	</td>
	<td align="left">
		<bean:define id="localIdValue" name="previewLocalCampaignForm" property="localId" type="java.lang.String"/>
		<bean:define id="imageWidthLocalValue" name="previewLocalCampaignForm" property="imageWidthLocal"
type="java.lang.String"/>
		<bean:define id="imageHeightLocalValue" name="previewLocalCampaignForm" property="imageHeightLocal"
type="java.lang.String"/>
		<%
			map = new HashMap();
			map.put("localId", localIdValue);
			map.put("isGlobalImage","false");
			pageContext.setAttribute("map", map, PageContext.PAGE_SCOPE);
		%>
		<html:img styleId="imagePreviewLocal" page="/loadCampaignImage.do" name="map" 
			width="<%=imageWidthLocalValue%>" height="<%=imageHeightLocalValue%>"/>
	</td>
</tr>


Thanks in advance,

Christina Siena


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message