| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs JSP FAQ:
What is difference between JSP and Servlet?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
What is difference between JSP and Servlet?JSP are simply the html pages with some Java code encapsulated in special tags. In another words, the JSP is Java code embedded in HTML context. The JSP files are converted internally into servlet classes completely before executed by the container on the server side. The client only sees the results of that code's execution mixed in appropriately with the html. The elements in a Java Server Page will generally be compiled by the JSP engine into a servlet, but the JSP specification only requires that the JSP page execution entity follow the Servlet Protocol.
Servlets are compiled pure Java classes extended from The advantage of JSP is that they are document-centric. Servlets are program oriented. A JSP can contain Java program fragments that instantiate and execute Java classes, but these occur inside an HTML template file and are primarily used to generate dynamic content. Some of the JSP functionality can be achieved on the client, using JavaScript. The power of JSP is that it is server-based and provides a framework for Web application development. Servlets and Java Server Pages are complementary APIs, both providing a means for generating dynamic Web content. Java Server Pages (JSPs) technology is an extension of Java servlet technology and combines HTML and Java code into a single file. While Java servlet technology focuses on Java classes capable of generating HTML output with PrintWriter.println() statements, JSP technology abstracts this concept to a higher level. With JavaServer Pages, a Web developer can write static HTML pages and simply add Java code in those sections of the page that need to be dynamically generated. Usually, JSP is used for presentation and Servlet is used for the processing. Basically, you should put all of your logic in the Servlet without any presentation logic. When complete, forward to a JSP page that contains only presentation logic without business logic. If done correctly, the servlet can forward to any number of JSPs (if configured) that will present the same data in many different ways. In such way, the content generation and content presentaion are seperated from each others. You can change the presentation without touching the business methods. From performance view, the first time when JSP engine encounter JSP request, it convert JSP in servlet, compile it and the bytecode format it saves in JSP Container along with the time stamp. Due to this process the first time response of JSP as compaired to servlets is slower, much slower. But from next request onword JSP engine checks the time stamp of the request and of JSP compiled file in JSP Container in JVM, and if the file is not changed then it redirects this request to that class file. And client get the response. |