Search code examples
cssjsp

Add image or text onto all JSP pages through Struts or CSS


I have a large number of JSP pages that need a small bit of static content added to them displayed in a fixed location. The content can appear over current page content. My question is, without making modifications to all 300 pages, is there a way to insert the content through Struts or CSS somehow?

For example, I want a logo to appear on all websites that I currently have, hovering at the bottom.

Note, I want to do this without making modifications to all 300 pages, and no, unfortunately the pages do not include menu header/footer files. I DO have a CSS page that is used though.


Solution

  • You might want to check out sitemesh. Read the documentation for the full installation and config details, but basically, for example, you could create a "master" decorator (think of a decorator like a skin, or template) like this:

    <div id="header">Whatever you want here</div>
    <div class="docBody"><decorator:body /></div>
    

    Next add this snippet to your web.xml

    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    

    and then sitmesh will intercept the request, and wrap the "master" decorator around the result from each jsp. In other words, the contents of each jsp will be rendered into <decorator:body>.