One thing worth pointing out about this is that you'll lose the benefit of fronting your app server with a web server... You won't be able to offload the serving of images, stylesheets and such, from the app server to the web server. That's probably not a big problem in many cases where a single server with a decent set of specs can handle the load anyway, but in a more robust "enterprise" environment, your really kind of defeating the purpose of a fleet of web servers in front of a number of app servers.

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

Dakota Jack wrote:
<snip>
On Sat, 29 Jan 2005 09:00:39 -0500, Frank W. Zammetti
<[EMAIL PROTECTED]> wrote:

Just from a curiosity standpoint Jack... I've already decided it's not
an approach I'd advocate, but I am interested to know how you serve
things like graphics and stylesheets from under WEB-INF.  I assume all
your graphics are actually server by an Action (a trick I've pulled when
serving images from a database), and I further assume your stylesheets
aren't just linked in...

</snip>


<img src='resource.do?file=whatever.jpg'>

<link
    href='resource.do?file=whatever.css'
    rel='stylesheet'
    type='text/css'>

You can also put this sort of Struts protocol into Flash ActionScript, etc.

To be complete on this list:

public final class ResourceAction
    extends Action {

  public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
      throws IOException,
             ServletException {
    String file = request.getParameter("file");
    String ext  = file.substring(file.lastIndexOf('.') + 1);
    String type = null;
    String path = null;

    if ("gif".equals(ext)) {
      type = "image/gif";
      path = path("gif");
    } else if ("jpg".equals(ext)) {
      type = "image/jpeg";
      path = path("jpeg");
    } else if ("css".equals(ext)) {
      type = "text/css";
      path = path("css");
    } else if ("flash".equals(ext)) {
      type = "application/x-shockwave-flash";
      path = path("flash");
    } else if ("text".equals(ext)) {
      type = "text/plain";
      path = path("text");
    } else if ("js".equals(ext)) {
      type = "text/javascript";
      path = path("js");
    } else if ("png".equals(ext)) {
      type = "image/png";
      path = path("png");
    } else if ("html".equals(ext)) {
      type = "text/html";
      path = path("html");
    } else if ("applet".equals(ext)) {
      type = "application/x-java-applet";
      path = "classes" + File.separator + "com" + File.separator +
"crackwillow" + File.separator + "applet";
    }

    String name = Classpath.WEB_INF + path + file;

    response.setContentType(type);
    response.setHeader("Cache-Control", "");
    response.setHeader("Pragma", "");
    response.setHeader("Expires", "");
    response.addHeader("Content-Disposition","filename=" + name);

    try {
      FileInputStream     fis   = new FileInputStream(name);
      BufferedInputStream bis   = new BufferedInputStream(fis);
      byte[]              bytes = new byte[bis.available()];
      OutputStream        os    = response.getOutputStream();
      bis.read(bytes);
      os.write(bytes);
      os.flush();
      os.close();
    } catch (IOException ioe) {
      StdOut.log(SiteConstant.ERROR_LOG,"ResourceAction: problem file
is: " + name + "\n" + StackTrace.trace(ioe) + "\n" +
ioe.getMessage());
    }

    return null;
  }

  private String path(String fileType) {
    return "resource" + File.separator + "content_type" +
File.separator + fileType + File.separator;
  }
} ///;-)






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to