answersLogoWhite

0

What is the servlet?

User Avatar

Anonymous

14y ago
Updated: 8/18/2019

The internet's original purpose was to access and copy files from one computer to another. While TCP/IP provided a highway layer, the File Transfer Protocol (FTP) specification provided a standard way to exchange those files. It defined a way of shuttling them back and forth, but said nothing about looking at the content. HyperText Markup Language (HTML) allowed us to see the documents on the Internet. FTP can transmit HTML files just as easily as HTTP can. But we use Hypertext Transfer Protocol (HTTP) to act as an FTP specifically for HTML documents because it is a stateless protocol which makes having many short connections more efficient.

HTTP is the Plumbing that connects the various computers. Now it is time to discuss about the fluid that flows through it "JSP & Servlets"

Note: JSP & Servlets arent the only technologies that are used in J2EE applications. Struts, Hibernate, Springs etc are other technologies that are used in J2EE Web applications. But, don't worry about them because they arent in the exam.

Using HTTP and HTML people were able to view/browse files and contents on a remote server. This is very useful, but people wanted live data. This is where the CGI (Common Gateway Interface) specification helped us. It helped us connect to databases and display stuff on the fly. The CGI specification was a major breakthrough in Web Application Development. The CGI standards made sure that the same CGI program worked on different Web servers.

CGI became the bread and butter of web developers. It was the most common means of displaying dynamic content on the internet. Though it was good, it wasn't good enough. It was not able to handle the performance requirements of the bursting Internet users. It was literally too much for it.

If you are asking me why CGI couldn't handle the load, the answer is simple. CGI spawned a separate process for every request that it receives. This design was able to sustain during off-peak hours but ate off server resources during peak loads which was eventually too much for it.

With growing numbers of users of web applications, scalability became a key consideration which wasn't CGI's Middle Name and hence people started exploring other options.

Many CGI derivatives came up as server-side programming solutions that implement business logic, including ASP, ColdFusion, PHP, and Perl. Java surpassed them all due to portability and its object oriented programming design.

Alas, he we are, learning JSPs and Servlets that are the children of the Java Family which make our lives all the more easier in the world of Web Development.

Java was conceptualized in 1991 but it wasn't in the internet programming world until 1997. Servlets were the alternative to CGI and were released in 1997. Unlike CGI, which starts a process for each request, Servlets just spawn a new thread. Servlets had a better or rather efficient architecture which was able to handle the loads of the internet.

Though Servlets were awesome when compared to CGI, they still had some issues when it came to displaying dynamic content on a web page. Thankfully, Sun released the JSP (Java Server Pages) specifications in 1998, which solved all our UI woes. JSPs enabled programmers to display dynamic HTML content that could also use Java features. The combination of JSPs and Servlets was just what the Doctor Prescribed and it just revolutionized the Web Programming industry.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

What are types of servlet?

Http servlet and Generic servlet


What is java servlet chaining?

Servlet Chaining means the output of one servlet act as a input to another servlet. Servlet Aliasing allows us to invoke more than one servlet in sequence when the URL is opened with a common servlet alias. The output from first Servlet is sent as input to other Servlet and so on. The Output from the last Servlet is sent back to the browser. The entire process is called Servlet Chaining.


Can insert javascript coding in servlet?

No. Javascript code can be present inside a JSP but not inside a servlet. A Servlet is a pure java class.


What is servlet mapping?

A Servlet Mapping is a directive in the web.xml that tells the Servlet Container which class to use when a particular Servlet is called. A Servlet is a class within your Java Web Application. Let's say you have a servlet called MyServlet in the com.example.servlet package. You would need to have a Servlet Mapping pointing the path "/MyServlet" to the "com.example.servlet.MyServlet" class. Without the servlet mapping, you would not be able to invoke your servlet because the Servlet container would not know where it is. JSPs are different - they do not need mappings like this. JSPs exist within the WebRoot of the application, so they are always available. Servlets exist in the WEB-INF\Classes directory once your application is deployed.


How does Apache httpd work?

Tomcat is a servlet container, and the following is how a servlet container works The init, service, and destroy methods are the servlet's lifecycle methods. The init method is called once by the servlet container after the servlet class has been instantiated to indicate to the servlet that it being placed into service. The init method must complete successfully before the servlet can receive any requests. A servlet programmer can override this method to write initialization code that needs to run only once, such as loading a database driver, initializing values, and so on. In other cases, this method is normally left blank. The service method is then called by the servlet container to allow the servlet to respond to a request. The servlet container passes a javax.servlet.ServletRequest object and a javax.servlet.ServletResponse object. The ServletRequest object contains the client's HTTP request information and the ServletResponse encapsulates the servlet's response. These two objects enable you to write custom code that determines how the servlet services the client request. The servlet container calls the destroy method before removing a servlet instance from service. This normally happens when the servlet container is shut down or when the servlet container needs some free memory. This method is called only after all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls destroy, it will not call the service method again on this servlet. The destroy method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, and threads) and make sure that any persistent state is synchronized with the servlet's current state in memory. For Better Picture, Visit below article full of images to clear the concept : http://shivasoft.in/blog/java/servlet/how-container-handles-the-servlet-request/


How the pass value from the HTML pages to the servlet?

You need a form to pass value to a servlet. In the form tag, the action element passes the value into the servlet.


How do you proove servlets are faster than JSP?

because JSP internally changes in servlet and then follow servlet life cycle, so it is slower than servlet


Describe the life cycle of servelet?

Each servlet has the same life cycle: * A server loads and initializes the servlet * The servlet handles zero or more client requests * The server removes the servlet (some servers do this step only when they shut down) == When a server loads a servlet, the server runs the servlet's init method. Initialization completes before client requests are handled and before the servlet is destroyed. Even though most servlets are run in multi-threaded servers, servlets have no concurrency issues during servlet initialization. The server calls the init method once, when the server loads the servlet, and will not call the init method again unless the server is reloading the servlet. The server can not reload a servlet until after the server has destroyed the servlet by calling the destroy method. == After initialization, the servlet is able to handle client requests. This part of the servlet life cycle was handled in the previous lesson. == Servlets run until the server are destroys them, for example, at the request of a system administrator. When a server destroys a servlet, the server runs the servlet's destroy method. The method is run once; the server will not run that servlet again until after the server reloads and reinitializes the servlet. When the destroy method runs, another thread might be running a service request. The Handling Service Threads at Servlet Termination lesson shows you how to provide a clean shutdown when there could be long-running threads still running service requests.


How to run servlet page in tomcat5.5 server?

How to run servlet page in tomcat5.5 server?"


How do you import jsp file in servlet?

I think the name of the jsp file is included in the web.xml of the servlet


How do you configure servlet and server for servlet chaining?

To configure servlet chaining, you need to set up multiple servlets in your web application, typically defined in the web.xml file or through annotations. Each servlet processes requests and can forward the response to the next servlet in the chain using the RequestDispatcher's forward() method. Ensure that each servlet is mapped to a specific URL pattern, allowing the initial request to reach the first servlet in the chain. Additionally, manage the flow by handling request attributes to pass data between servlets as needed.


Difference between servlet engines and servlet chaining?

Servlet engines are software components that manage the execution of servlets, handling requests and responses, and providing an environment for servlets to run within a web server. In contrast, servlet chaining refers to the practice of invoking multiple servlets in a sequence, where the output of one servlet can be passed as input to another, allowing for modular and reusable components in web applications. Essentially, servlet engines provide the infrastructure, while servlet chaining is a design technique for enhancing functionality within that infrastructure.