Technically(simply speaking) there is not difference between a JSP page and a Servlet since the JSP is compiled into a servlet by the container that you are using. Fundamentally though, JSPs and servlets are completely different. Servlets are the work horses of Java web technology, they have the full power of the Java language and can output HTML using the print writer. Essentially your dynamic data will be created/processed using servlets. The problem with servlets is essentially a simple one to understand. To output a single line of HTML you have to do the following; out.println("Hello"); // Can you imagine 30, 40, 50 , maybe even a hundred of these ... and then having to maintain it? To output a line of HTML you need to print it out. Now this is not so much of a problem if you are creating a dynamic table or if your web page is very small but for more complex pages that are much larger, you would go crazy with placing these HTML statements into the out.println(); statement above. Not to mention that you need to filter any special characters like the \ or the " . So even though Servlets are powerful they can get tedious with larger pages.
JSP (Java server Pages)were created after Servlets to address the problem of the out.println();. JSPs are formatted much like the typical HTML pages with the ability to use all the major scripting languages. JSP has, like servlets, the access to the full power of the Java language. The important to remember that JSPs are the presentation side of the page you are building. Because of this you should always strive for the separation of Java Code from the JSP. We want to do this so that our HTML developers can edit the page with out having to know any Java code. We can utilize tag libraries and make available tools in that manner but when ever possible we do not use java code in JSP (unless we really really really have to )
Both technologies have their purpose and I am sure that you could use each technology on its own but I have found that together they are a formidable combination in terms of design methodology, flexibility and power. JSP as the presentation and Servlets hard at work, behind the scenes, serving up your dynamic data and processing your complex algorithms.( No Al Gore didn’t invent the Algorithm … ok that sounded funnier in my head ) "For more, see the Marty Hall book." - Anthony The webpages to his books are called CORE servlets and Java server pages and MORE servlets and java server pages Here is a link to the SUN tutorials and specifically to the Java Server pages short course and the Servlets short course. Once you have an understanding of how each technology works, perhaps you should review a design methodoloy like MVC. MVC == the following; M = model or the business logic (database access, typically Servlet) V = view represents what the client sees (JSP) C = Controller is a servlet that forwards requests to the View and models respectively. If your application is a simple one you should still try to maintain the MVC (or model 2)structure as much as possible. Consider this good habit forming. You can find information on the MVC or Model 2 design patters here; Here is SUN's representation of the MVC architecture: http://java.sun.com/blueprints/patterns/j2ee_patterns/model_view_controller/ Here is another good description of the MVC architecture: http://www.cs.indiana.edu/~cbaray/projects/mvc.html Once you have mastered the MVC (model 2) architecture, try your hand at the STRUTS design pattern. I wouldnt try struts until you are firm in your knowledge of MVC. STRUTS located here; http://jakarta.apache.org/struts/
I hope this helps [ August 13, 2002: Message edited by: Steven Kors ]