tags:

views:

55

answers:

5

I am designing a small website using HTML + JSP.

This is my first time using JSP, though previously I have used PHP to make pages. One thing i found was that when i was making separate pages, i was copy + pasting the layout code of the site into each page, and then adding the content. This seems extremely inneficient, and I was wondering what is the most common practice for doing this?

One idea I had was to have a main index.jsp page that contains the layout code, and then use GET to pass a new page reuest to index.jsp. So to go to the "products" page you would type index.jsp?page=products, and a case statement in the index.jsp file would print the correct content.

I am a beginner in web design, so i would really appreciate any info or links on this topic.

+1  A: 

There are a lot of different ways to do what you need. One that I've used in the past is SiteMesh. SiteMesh seemed to work pretty well for me, YMMV.

Matthew J Morrison
Thanks for the tip, though I am trying to learn and make my own.
Kris M
You're trying to learn how to make your own.... your own what? Web design framework? If there is anything that the Java platform offers it is a huge selection of frameworks that make it easier to accomplish your goal. If your goal is to be able to reuse JSP fragments to make your design more DRY, take advantage of some of the frameworks available.
Matthew J Morrison
A: 

check this link it a video tut teach you frontend designing http://net.tutsplus.com/articles/news/professional-frontend-engineering/

i will try to get more and i will add it to this post

link1 : http://net.tutsplus.com/tutorials/tools-and-tips/how-using-state-diagrams-can-make-you-a-better-web-coder/

have a nice day

Jaison Justus
+3  A: 

A common (and simple) approach is to break your HTML up into commons sections (header, footer, sidebar, etc.). You then put these sections in their own .jsp file and include them on all pages:

  • header.jsp: contains all header markup
  • footer.jsp: contains all footer markup
  • sidebar.jsp: contains all sidebar markup

That way if you ever need to modify one of the common sections, you only need to update the included .jsp, rather than all pages.

Pat
I am trying this right now, it seems like a neat idea...
Kris M
+1  A: 

In Java (and JSP), theses problems are handled by frameworks.

If you want to code JSP, the historical graphic framework (still used) is probably Struts. I think it is a good choice to start, since you'll find a lot of tutorials on the internet.

In this framework, the layout problem is resolved by the "Struts-tiles" extension, where you can define a layout and the content in separate files that are merged at runtime.

Benoit Courtine
In just about everything this is supported by frameworks.
A: 

If you are using any web framework then I would suggest you use the methods the framework suggest. If you are not using a framework then I highly recommend you start using one, e.g. Struts.

I would aim to use an open source framework since it's very convenient to see the code that's happening behind the scenes and be able to debug through it. Here is a more complete list of all open source java frameworks.

Avoid all Copy-Paste methods at all time. It will only make your code repetitive and unmaintainable in the long run.

armannvg
That's from the old ages when the `jsp:include` wasn't introduced yet.
BalusC
True, I'll update the answer
armannvg