This email has spaces, etc., so let's see if it has this when it arrives there. If not, sorry.

Presently I load images as follows, since I want to control who has access to my images and other like resources. First, an Action subclass, viz. ActionStaticResource, cf. infra, to retrieve and to deliver the image, letting me store the image inside WEB-INF and isolated from the outside. Second, I access the image via an html:link html:img call in Struts, e.g.:

FOR CSS

<html:link href='staticResource.MichaelMcGradyHomeSites?content_type=text/plain&resource_source=css/index_css.css'/>

Or:

FOR IMAGES
<html:img src='staticResource.MichaelMcGradyHomeSites?content_type=image/gif&resource_source=graphics/struts-power.gif'


alt='Powered by Struts'
height='15'/>
(I use ".MichaelMcGradyHomeSites" instead of ".do", free ads, you know!) This includes the appropriate references in the struts-config.xml to:


  <global-forwards>
    //....
    <forward name='staticResource'
             path='/staticResource.MichaelMcGradyHomeSites'/>
    //....
  </global-forwards>

And:


<action-mappings> //.... <action path='/staticResource' type='com.michaelmcgrady.struts.action.ActionStaticResource' scope='request' input='staticResource'> <forward name='staticResource' path='staticResource'/> </action> //.... </action-mappings>




public final class ActionStaticResource extends Action {

  public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
      throws IOException,
             ServletException {

response.setContentType(request.getParameter(StaticResource.CONTENT_TYPE));

try {
String fileName = WEB_INF.getClasspath() + request.getParameter(StaticResource.RESOURCE_SOURCE);
FileInputStream fis = new FileInputStream(fileName);
byte[] imageBuf = new byte[1024];
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] bytes = new byte[bis.available()];
OutputStream os = response.getOutputStream();


      bis.read(bytes);
      os.write(bytes);
    } catch(Exception e) { System.out.println(e);}
    return null;
  }
} /// ;-)


I have tried to apply this strategy to SWF (Flash) files, using hints I have received before. But, I have not succeeded. I am a slow learner, I guess. I am not sure what I am doing wrong. Does anyone have a strategy?


Thanks for any help

Reply via email to