Originally posted by s.r.k.reddy: [My personal opinion servlets are the best in long run but both have got their own adv and disadv.[/QB]
I very much agree that both have got their own adv and disadv but how is that 'My personal opinion servlets are the best in long run '. Servlets and JSPs have their own functionality though technically they are same. JSPs are used for display purpose and Servlets may act as Controllers.
A servlet is a component of a Java "web application" that resides in a web container. Most of the Java objects and resources handled by the servlet is managed by the servlet container. It means you don't have to explicitly manage these things in your servlet code. However, you have to specify these settings in a special file called a deployment descriptor. A client can "invoke" the services of a servlet indirectly by making an HTTP request through his browser. Meaningful data like request parameters (through HTML controls) can be sent to the servlet via HTTP. After the servlet evaluates the data, it now prepares a response, usually in the form of an HTML file which is sent back to the client. Other files, or "content-types" are certainly possible. For practical purposes, it is advisable to separate the business logic (evaluating the raw data into some meaningful result) from presentation logic (creating the actual HTML response file). JSPs were created specifically to deal with presentation logic, and to allow servlets to exclusively deal with the business logic. JSPs can be considered as templates for your public web pages. Also, a JSP is a special kind of servlet, and the objects it uses are also container managed. So it is also another kind of component. A "web application" is a collection of servlets and JSPs working in unison with a definite workflow. HTH
1st thing: "vethadas"- Welcome to the JavaRanch! Please adjust your displayed name to match the JavaRanch Naming Policy. You can change it here. Thanks! and again welcome to the JavaRanch! 2nd thing: Check out this thread --> JSP vs Servlets
Here's a simplified explaination: First, when most people refer to a servlet, they actually mean an object of class HttpServlet (not it's parent class Servlet). When I refer to a servlet, think "HttpServlet". A servlet is an object who has the ability to communicate with a web browser. It receives requests from a browser. These requests can ask for a web page, or they can be data that a user entered on a web page, and/or a command to run some process. To code one of these, all you have to do is declare your a class that extends HttpServlet, override the doGet and/or doPost method. It is in these methods that you add your own code to do whatever you want. To send a webpage back to the browser, all you need to do is write HTML code as Strings inside println statements. JSP pages came after developers tired of writing HTML strings in println statements. After all, why should an HTML developer also have to know Java to create a webpage? JSP pages are basically a traditional HTML page that *magically* compile into Servlets. They have some extra features as well. For instance, a developer can call a "traditional" java object to do some processing inside the JSP page. So with JSP, an HTML developer needs to know less Java (although some knowledge is required) than before. I would also argue that a "Web Application" is a client/server app that uses a browser for the client. In the java world, web apps use servlets and/or JSPs to communicate with a browser. They can also use (and frequently do) traditional java classes to do much of the processing that is not involved with communicating with the browser.
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
how do I do my own kindle-like thing - without amazon