4 Replies Latest reply on Jul 28, 2006 4:41 PM by jleech

    Serving dynamically generated JSPs

      We have an appliacation that needs to dynamically generate JSPs and make them available for our customers to access. Can someone point me to how I can serve a jsp that is stored say in a database to an end user?

      Right now, we've deployed our application as an exploded war (well, actually an exploded ear since ejbs are a part of the app). We use a servlet with an id parameter to reference the jsp that needs to be served. The servlet currently loads that jsp from the database and writes it to a temporary file on disk within the exploded war. It then redirects to that termporary jsp file.

      For several reasons, we need to stop doing it this way. The basic reason is that we need to deploy our application as an archive, not exploded. As such, we can no longer write the temporary file. Any suggestions on how to serve this programmatically generated jsp without writing the file to disk first?

      Thanks,
      Matt

        • 1. Re: Serving dynamically generated JSPs
          peterj

          This is probably not the solution you are looking for, but have you looked into using Velocity templates (or some of the other templating mechanism) instead of JSPs? If you are already passing beans to the JSPs and using JSTL to extract the bean data and generate the HTML, this would be very easy to convert to Velocity. Of course, if you have a lot of server-side Java code embedded in your JSPs then you would have a lot more work to do.

          • 2. Re: Serving dynamically generated JSPs
            peterj

            I guess I could always point out that when you deploy an ear or war file that JBoss will explode the contents inot a subdirectory of server/xxx/tmp/deploy. The tricky part is determining the subdirectory name since the name contains a random 5-digit integer. But if you can overcome that obstacle, perhaps you can place the JSPs within there. Not sure if that would work, but you could try it by hand once first.

            • 3. Re: Serving dynamically generated JSPs

              I'll take a look at Velocity...one of the reasons we didn't look at an existing templating engine is we have a lot of very specific business logic with how the templates are managed, who can make what changes, etc, etc...

              As for the temp directory, I thought about that too but it made me uncomfortable. Who knows how the temp directory structure might change with different versions of JBoss. Or even what guarantee there is that files written into there are available how I want. I guess before I jump down that road I'd want some input from a JBoss developer that it's "OK".

              • 4. Re: Serving dynamically generated JSPs
                jleech

                I would do something along the lines of compiling the .jsp into a servlet and dynamically loading it / invoking it.