Separate Static Content From Dynamic Content

When I get a few minutes I'll add more here. However, suffice it to say for the moment that keeping these two separate is key to using JavaServerPages especially when combined with JavaServlets and JavaBeans in a ModelViewController architecture.

-- KyleBrown

Microsoft ActiveServerPages encourage mixing static and dynamic content.

-- EricUlevik


I think Kyle and Eric are saying the same thing in a different way. Both JSP and ASP define the static content and include markers where the dynamic content is placed (by COM components or JavaBeans respectively).

<H1>This is static</H1>
<BEAN: insert dynamic here> (or <OBJECT: insert dynamic here>)
<H1> Static again</H1>

So in one sense, static and dynamic are separated, and in another, they are mixed.


Netscape's Server-side JavaScript also allows (I wouldn't necessarily say encourages) static and dynamic content to be jumbled together.

<SCRIPT>
  JavaScript to be run in the client browser
</SCRIPT>
<H1>I'm static</H2>
<SERVER>
  JavaScript to be run on the server as the page is being served up
  which might print more HTML or client-side JavaScript
</SERVER>
<B>More static</B>
<SERVER>
  More server code, (running in the same execution context, so all the 
  variables from the previous <SERVER></SERVER> chunk still exist
</SERVER>
<I>Help me!</I>

I fell into this trap once and quite enjoyed myself for a while - but never again.

-- JezHiggins

I think ASP allows you to do the same with <% server side VBScript %>.


Kyle's comment above referring to MVC is important. In web pages, the dynamic content is analogous to the Model. The static content is all presentation: it's the View.

The drive to separate these two things is one of the big draws (for some) of using XML on the server. One server-side process generates the dynamic content as an XML document that contains no static presentation-oriented content at all:

    <ticket-quote>
        <departure>
            <location>DFW</location>
            <time>11:45 am 11/05/1999</time>
        </departure>
        <arrival>
        ...
    </ticket-quote>

(I just made that up; it's not an instance of any XML document type I know of.)

Then something else --- another server-side process, probably, but perhaps also the browser --- takes that data and injects it appropriately into the static content. In the browser, that process would probably be directed by some sort of stylesheet; the same could be true on the server, if desired.

I don't have much experience with this way of doing things, so I don't know how well it works in practice. But the idea appeals to me. -- GlennVanderburg


EditText of this page (last edited September 4, 2006) or FindPage with title or text search