In the previous chapter we looked at the history of the Web (Internet) and how JSPs and Servlets came into being. As you might have already guessed by now, any J2EE application needs a server on which it runs. It is called a Web Server. Also, the Servlet needs something in which it would run (Think of the JVM in which all java applications run) and that is called the Servlet container.
In this chapter, we are going to take a look at these two entities.
So, lets get started!!!
Web Servers and Servlet Containers
A servlet is nothing but Java code that runs in a container. It generates HTML & other contents that get displayed in the web page that we see. It is purely coded in Java, so the benefits and restrictions of all regular Java classes apply here too. Servlets are compiled to form a platform neutral bytecode (All java code is platform neutral, isnt it? Serlvet is no different). Upon request, this bytecode file is loaded into a container. Some containers (servlet engines) are integrated with the Web server, while others are plug-ins or extensions to Web servers that run inside the JVM. Servlets look the same as static Web pages to the client, but they really are complete programs capable of complex operations.
The servlet container is an extension of a Web server in the same way CGI, ASP, and PHP are. A servlet functions just like them, but the language in which it is written is Java. That's the main difference. The servlet doesn't talk to the client directly. The Web server functions as the intermediary that does it for the servlet. In a chain of processes, the client sends a request to the Web server, which hands it to the container, which hands it to the servlet. The Servlet processes the request and generates a response. The response starts from the servlet and goes to the container and then to the Web server and back to the client. Of course there are several other steps that happen too but this is just the introduction so this much would suffice I believe.
The servlet architecture makes the container manage servlets through their lifecycle. The container invokes a servlet upon receiving an HTTP request, providing that servlet with request information and the container configurations. The servlet uses this to do its job which is processing the data it received as part of the request. When finished, it hands back HTML and objects that hold information about the response. The container then forms an HTTP response and returns it to the client which inturn displays the stuff sent by the Servlet on screen in the web browser.
Below is a simple illustration of the flow of control that starts and ends at the Web Browser. Control starts at the browser, goes to the server and then to the container which in turn invokes the Servlet. Our Servlet happily does the processing (which might involve hitting a database) and returns the data to the container which in turn passes it on to the web server which finally displays the contents on the web browser.
The Servlet container is often written in Java, since it eventually runs inside a JVM. However, some vendors implement their containers in different languages (they aren’t essentially bound to Java). The point here is the fact that, all we need is a servlet container that can read and execute our servlets. The language in which it is implemented is not necessarily important for us.
Previous Chapter: Chapter 1 - Servlet & JSP History
Next Chapter: A Sample Servlet
Monday, February 28, 2011
Chapter 2: Web Servers and Servlet Containers
Labels:
containers,
jsp,
jsp and servlets,
scwcd,
scwcd certification,
servlet container,
servlets,
web server,
web servers
| Reactions: |
Subscribe to:
Post Comments (Atom)
© 2013 by www.inheritingjava.blogspot.com. All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.
Popular Posts
-
The following are some questions that you might encounter when you face an Interview for a position of a Senior Java/J2EE Developer. Design ...
-
The following are some questions you might encounter with respect to Java Multi-threading in any Interview. Multi-threading is a powerful an...
-
The following are some questions you might encounter with respect to Java Server Pages or JSPs in any Interview. JSPs are an integral part o...
-
Access Modifiers are one of the most important topics when it comes to taking the SCJP exam. You can expect a number of questions from these...
-
Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the a...
-
1. Does Hibernate implement its functionality using a minimal number of database queries to ensure optimal output? Hibernate can make cert...
-
The last thing we need to look at in our series of chapters on threads, is how threads can interact with one another to communicate about, a...
-
You might be wondering, is Stack and Heap such a large topic that I have dedicated one full chapter to it? Actually it isnt such a big topic...
-
In the chapter on Inner classes, I had promised that we will look in more detail about the different types of inner classes. Well here we ar...
-
This chapter is probably going to be the most important or rather most confusing chapter from the exam perspective. You can expect atleast a...


No comments:
Post a Comment