You must Sign In to post a response.
  • Category: General

    what is the main difference between jsp and servlets?

    What is the main difference between jsp and servlets?

    Please help me about this issue.
  • #55187
    JSP and Servlets both define server end functionality. They both are complementary API's, and provides the basis for generating dynamic contents. But, they differ each other only in terms of their representation and their execution cycle.

    Servlets are pure JAVA programs and are full functional JAVA codes, and here HTML cannot be used, whereas in JSP, HTML use is allowed, so that we can use and modify the contents. Again, in Servlets, client side validation is possible, but in JSP client side validation is not possible. Another point to be noted is that JSP programs will be converted into servlets and only then executed, and so it takes more time, and so servlets are faster.

    Well, the main advantage of JSP is that they are more of a document-centric, while Servlets look and act like programs. And since JSP is server-based, it provides a framework for web application development, and creating dynamic content. But, there is nothing like choosing JSP or Servlet, they are used as a combination and are designed into a unified framework.


  • #55218
    JSP and Servlet both define the server end functionality to provide dynamic outputs ,As we know our HTML is only the client end technology version which runs on client browser. JSP and Servlet differ each other in terms of represntation and execution cycle. Servlet are full functional java codes that define the output like write to stream files in protocol defined ways, JSP on the other hand is Role Sepated format to do so where a ordinary web designer designes how will be the presentation of the data and Programmer defines the functinality to provide the underlying things represented in conditional and non conditinal ways , But here is the magic of JSp that merges the both HTML represntation mixed with JAVA scriptlets.
    Thanks !!

  • #55950
    hi mr misra
    you have asked a very nice question.
    here i have tried to answer this question.
    Servlets and Java Server Pages are complementary APIs, both providing a means for generating dynamic Web content. A servlet is a Java class implementing the javax.servlet.Servlet interface that runs within a Web or application server's servlet engine, servicing client requests forwarded to it through the server. A Java Server Page is a slightly more complicated beast. JSP pages contain a mixture of HTML, Java scripts (not to be confused with JavaScript), JSP elements, and JSP directives. 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.

    The advantage of Java Server Pages is that they are document-centric. Servlets, on the other hand, look and act like programs. A Java Server Page 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. Rather than choosing between servlets and Java Server Pages, you will find that most non-trivial applications will want to use a combination of JSP and servlets. In fact, the JSP 1.1 and Servlet 2.2 specifications are based around the concept of the Web application, combining the two APIs into a unified framework

  • #55952
    here some datas about the java servlets !!!
    What are Java Servlets?
    Servlets are Java technology's answer to CGI programming. They are programs that run on a Web server and build Web pages. Building Web pages on the fly is useful (and commonly done) for a number of reasons:
    The Web page is based on data submitted by the user. For example the results pages from search engines are generated this way, and programs that process orders for e-commerce sites do this as well.
    The data changes frequently. For example, a weather-report or news headlines page might build the page dynamically, perhaps returning a previously built page if it is still up to date.
    The Web page uses information from corporate databases or other such sources. For example, you would use this for making a Web page at an on-line store that lists current prices and number of items in stock.
    2. What are the Advantage of Servlets Over "Traditional" CGI?
    Java servlets are more efficient, easier to use, more powerful, more portable, and cheaper than traditional CGI and than many alternative CGI-like technologies. (More importantly, servlet developers get paid more than Perl programmers :-).
    Efficient. With traditional CGI, a new process is started for each HTTP request. If the CGI program does a relatively fast operation, the overhead of starting the process can dominate the execution time. With servlets, the Java Virtual Machine stays up, and each request is handled by a lightweight Java thread, not a heavyweight operating system process. Similarly, in traditional CGI, if there are N simultaneous request to the same CGI program, then the code for the CGI program is loaded into memory N times. With servlets, however, there are N threads but only a single copy of the servlet class. Servlets also have more alternatives than do regular CGI programs for optimizations such as caching previous computations, keeping database connections open, and the like.
    Convenient. Hey, you already know Java. Why learn Perl too? Besides the convenience of being able to use a familiar language, servlets have an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions, and many other such utilities.
    Powerful. Java servlets let you easily do several things that are difficult or impossible with regular CGI. For one thing, servlets can talk directly to the Web server (regular CGI programs can't). This simplifies operations that need to look up images and other data stored in standard places. Servlets can also share data among each other, making useful things like database connection pools easy to implement. They can also maintain information from request to request, simplifying things like session tracking and caching of previous computations.
    Portable. Servlets are written in Java and follow a well-standardized API. Consequently, servlets written for, say I-Planet Enterprise Server can run virtually unchanged on Apache, Microsoft IIS, or WebStar. Servlets are supported directly or via a plugin on almost every major Web server.
    Inexpensive. There are a number of free or very inexpensive Web servers available that are good for "personal" use or low-volume Web sites. However, with the major exception of Apache, which is free, most commercial-quality Web servers are relatively expensive. Nevertheless, once you have a Web server, no matter the cost of that server, adding servlet support to it (if it doesn't come preconfigured to support servlets) is generally free or cheap.

  • #55955
    here i have collected some data for the jsp

    Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations. But most CGI variations, including servlets, make you generate the entire page via your program, even though most of it is always the same. JSP lets you create the two parts separately. Here's an example:

    Welcome to Our Store

    Welcome to Our Store


    <% out.println(Utils.getUserNameFromCookie(request)); %>
    To access your account settings, click

    Regular HTML for all the rest of the on-line store's Web page.

  • #55957
    What are the Advantages of JSP?
    vs. Active Server Pages (ASP). ASP is a similar technology from Microsoft. The advantages of JSP are twofold. First, the dynamic part is written in Java, not Visual Basic or other MS-specific language, so it is more powerful and easier to use. Second, it is portable to other operating systems and non-Microsoft Web servers.
    vs. Pure Servlets. JSP doesn't give you anything that you couldn't in principle do with a servlet. But it is more convenient to write (and to modify!) regular HTML than to have a zillion println statements that generate the HTML. Plus, by separating the look from the content you can put different people on different tasks: your Web page design experts can build the HTML, leaving places for your servlet programmers to insert the dynamic content.
    vs. Server-Side Includes (SSI). SSI is a widely-supported technology for including externally-defined pieces into a static Web page. JSP is better because it lets you use servlets instead of a separate program to generate that dynamic part. Besides, SSI is really only intended for simple inclusions, not for "real" programs that use form data, make database connections, and the like.
    vs. JavaScript. JavaScript can generate HTML dynamically on the client. This is a useful capability, but only handles situations where the dynamic information is based on the client's environment. With the exception of cookies, HTTP and form submission data is not available to JavaScript. And, since it runs on the client, JavaScript can't access server-side resources like databases, catalogs, pricing information, and the like.
    vs. Static HTML. Regular HTML, of course, cannot contain dynamic information. JSP is so easy and convenient that it is quite feasible to augment HTML pages that only benefit marginally by the insertion of small amounts of dynamic data. Previously, the cost of using dynamic data would preclude its use in all but the most valuable instances.

  • #55958
    JSP Versus Java Servlets

    Before the advent of JSP, the most-used Java technology that could generate dynamic Web page content was Java servlets. Because JSPs eventually are compiled into Java servlets, you can do as much with JSPs as you can do with Java servlets.

    However, coding JSPs is easier than coding Java servlets. With JSPs, you place static text by coding HTML tags as opposed to Java servlets, in which you place static text by coding a plentitude of println statements.

    With JSPs, you change static text by changing HTML; and with Java servlets, you change static text by modifying a Java servlet (don t forget the compile/debug cycle!).

  • #55959
    JSP Versus Active Server Pages

    Active Server Pages (ASP) is the Microsoft solution for providing dynamic Web content. Actually, ASP looks very similar to JSP; both use custom tags to implement business logic and text (HTML) for invariant Web page parts.

    However, the devil is in the details, as described in the following: l ASP uses VBScript or JScript, a Microsoft flavor of JavaScript, as its scripting language, whereas JSP uses Java, a more powerful language than VBScript or JScript.

    The ASP developer typically uses a Microsoft Web server platform or requires a third party product that permits ASP execution on non-Microsoft platforms.

    The JSP developer has a wide variety of Web server platforms available for use. Note These third parties must port Microsoft software components, such as ActiveX, to different platforms in order for ASP to be used on these platforms. l An ASP is interpreted every time the page is invoked, whereas a JSP is interpreted
    only the first time the page is invoked (or when the page is changed).

    However, Microsoft has overcome the previously mentioned limitations of ASP
    with its release of ASP.NET. ASP.NET, formerly ASP+, promises to be a serious contender against JSP. As of this writing, you may download the ASP.NET Beta-2 release from

    JSPs Versus Client-Side Scripting

    Client-side scripting with JavaScript or VBScript is certainly handy and useful, but it does present several problems, including the following:

    - You must count on the customer's browser to have scripting enabled, which, of course, you can t.

    - Different customers may use different browsers. And coding client-side scripts that work on different browsers can be a headache.

    - Scripting languages used on the client side cannot match the strength and versatility of Java.

    - Client-side scripting languages have very limited access to server-side resources, such as databases. JavaServer pages have access to all server-side resources within the well-defined architecture of J2EE.

  • #58654
    I would like to figure out some points. JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Servlets, make you generate the entire page via your program, even though most of it is always the same. JSP lets you create the two parts separately. Java Server Pages (JSP) is a Sun Microsystems specification for combining Java with HTML to provide dynamic content for Web pages. When you create dynamic content, JSPs are more convenient to write than HTTP servlets because they allow you to embed Java code directly into your HTML pages, in contrast with HTTP servlets, in which you embed HTML inside Java code. JSP is part of the Java 2 Enterprise Edition.
    As JSP s are converted into servlet classes, functionally there is no difference between both the methods. Only difference i expect is JSP s are HTTPServlet where as servlet is either GenericServlet or HTTPServlet. So JSP service method always contains the parameters HTTPServletRequest and HTTPServletResponse. In case of HTTPServlet, service method is doPost or doGet etc and contains parameters HTTPServletRequest and HTTPServletResponse. In case of GenericServlet parameters of service method are ServletResponse and ServletRequest. In servlets these methods throw ServletException.

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.