4 Replies Latest reply on Sep 16, 2003 2:45 AM by justkeys

    return binary content from jsp page

    justkeys

      Is it possible in Jetty to return for example application/x-zip-compressed OR text/html, depending on the request?

      Because, as i understand, the content type is automatically set to "text/html; charset=ISO-..." if you don't explicitly use the <%@page contentType="..."%>. When i look into the .java file generated from the jsp, this is indeed the first thing that is done.

      If so, how can i set the content type, depending on the request parameters, using jsp?

        • 1. Re: return binary content from jsp page
          jonlee

          Response type is controlled through the Java statement:
          response.setContentType("text/html");

          If you do this before any stream output is generated in your JSP you will override the default content type. So your embedded Java code must perform this before any out.print... statements are generated in your JSP->Java.

          We usually generate this programmatic output through servlets because we can create a HashMap lookup in the servlet initializer (this only executes once when the servlet object is created). You can then use the HashMap to select the required content-type string.

          YMMV.

          • 2. Re: return binary content from jsp page
            justkeys

            I know that; the problem is that the very same code does generate a valid zip file in tomcat, and does generate a corrupt zip file in jetty. Same machine, same jvm, same jboss 3.2

            That is because during the download, jetty corrupts the stream, probably because it overides the content type somehow.

            The zipfile from jetty appears to be corrupt when i try to open it (after download), the one from tomcat opens without problems.

            • 3. Re: return binary content from jsp page
              jonlee

              It is possible, I suppose. As I said, we don't use JSPs, we use servlets for this type of work. We haven't had an issue in Jetty with either HTTPS or HTTP streams, doing JPEG, GIF, PDF or DOC. I could test our code with ZIP if that would help confirm operation for you. Actually, we haven't seen an issue with JSPs delivering WAP content either.

              Post the generated Java code from the JSP so the folks can have a look at it. Perhaps there is something else going on.

              Perhaps as a test, you might want to try the same code with delivery of other binary types just by way of experiment.

              Since Jetty uses Jasper, like Tomcat, I'm fairly certain that the generated servlet code itself should be the same for either platform. I'd be interested in determining the issue here.

              • 4. Re: return binary content from jsp page
                justkeys

                This code returns a valid zip stream in jboss/tomcat 3.2 RC2, and an invalid zip stream in jboss/jetty 3.2 RC2.

                The main jsp file in view.jps; it includes TabsFramePre.jsp. This one receives a model from a ModelBuilder, which might be a SendBinary.Data object,. In that case, the response is handled by the SendBinary class, that sets the content type, and the sends binary content.

                good luck