Announcement Announcement Module
Collapse
No announcement yet.
How do I get the same header and footer for all pages??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I get the same header and footer for all pages???

    Hi,
    I've just started playing around with Spring MVC so this might be a complete newbie question. Never the less, I can't seem to find an answer in the forum or docs.

    I am building a simple webapp with approx. 10-15 different JSP-pages such as "add person", "edit person", "display jobs" etc. This works fine with Spring MVC, data access layer etc.

    My problem is that now I want to have a uniform look and feel on every page. Specifically, I want the same header, footer and left-margin menu on every page. I don't want repeat this code in all 10-15 pages. I'd rather include the primary jsp in a page where the header, footer and menu is set with correct layout. How do I accomplish this with regard to controllers etc??

    If there's no simple answer, then please direct me to sample apps etc so that I might study the code there.

  • #2
    <%@ include file="header.jsp" %>

    ...
    ...
    ...

    <%@ include file="footer.jsp" %>


    Or you could use Struts Tiles.

    Comment


    • #3
      You should look into using Sitemesh of this. I've been using it for a while now for page decoration and it works really well.

      Sanjiv

      Comment


      • #4
        thanks

        I don't know Sitemesh but I'll look into it. The idea of decorating my pages seems interesting.

        Regarding kwest's answer: Your solution doesn't solve the problem since I'd also like the left-margin menu and the overall layout to be present on all pages without having to copy paste it into each jsp.

        Comment


        • #5
          I have an idea

          I too am looking to do a similar thing within the next few days. I have given it some thought and my plan was this:

          1. Construct a root.jsp page which holds the main skeleton of each page including headers, footer, left nav, etc.
          2. The mapping for all relevent pages will be to a controller which forwards to this view.
          3. In the controller, work out what the actual page request was and use that for the main page include (by adding it to the request scope and using the value in the jsp).

          here's a run thorugh to make it clearer:

          1. url looks like this: http://localhost/myapp/somepage.html
          2. somepage.html maps to the RootController (as do all pages that require this look and feel).
          3. In RootController, deduce the page requested was somepage.html and add to the model.
          4. Forward to root.jsp.
          5. In root.jsp, use the value of the requested resource as the main page include.

          Like i said its all in my head as a plan at the moment but i think it would work well. Let me know if you see any problems with this approach.

          Rakesh

          Comment


          • #6
            Rakesh,
            You are reinventing a solution that Sitemesh (http://www.opensymphony.com/sitemesh/) handles perfectly.

            Sitemesh is really easy to learn and you should be able to configure and set it up in a matter of days.

            Sanjiv

            Comment


            • #7
              Hi sanjiv,

              I have just spent the last couple of hours looking at sitemesh and I have to admit I will probably go with it. There's a very good tutorial at java.net that was very helpful to get started http://today.java.net/pub/a/today/20.../sitemesh.html.

              thanks for that tip Sanjiv,

              Rakesh

              Comment


              • #8
                The link does not work



                Please post the correct link, I am very curious

                Comment


                • #9
                  aplogies, the url has an extra '.' on the end!

                  http://today.java.net/pub/a/today/20.../sitemesh.html

                  Rakesh

                  Comment


                  • #10
                    Use of tiles versus sitemesh often comes up. Here's a good blog that explains the difference between the two related libraries.

                    http://www.jroller.com/page/dgeary/W...tiles?catname=

                    Pick the one that you feel better suites your needs.

                    Sanjiv

                    Comment

                    Working...
                    X