Photo:1 Photo:2 Photo:3 Photo:4 |
| History | |
| 2>
The complete servlet specification was created by Sun Microsystems, with version 1.0 finalized in June 1997. Starting with version 2.3, the servlet specification was developed under the Java Community Process. JSR 53 defined both the Servlet 2.3 and JavaServer Page 1.2 specifications. JSR 154 specifies the Servlet 2.4 and 2.5 specifications. As of March 26, 2010, the current version of the servlet specification is 3.0.
In his blog on java.net, Sun veteran and GlassFish lead Jim Driscoll details the history of servlet technology. James Gosling first thought of servlets in the early days of Java, but the concept did not become a product until Sun shipped the Java Web Server product. This was before what is now the Java Platform, Enterprise Edition was made into a specification.
Servlet API history
Servlet API version
Released
Platform
Important Changes
Servlet 3.0
December 2009
JavaEE 6, JavaSE 6
Pluggability, Ease of development, Async Servlet, Security, File Uploading
Servlet 2.5
September 2005
JavaEE 5, JavaSE 5
Requires JavaSE 5, supports annotation
Servlet 2.4
November 2003
J2EE 1.4, J2SE 1.3
web.xml uses XML Schema
Servlet 2.3
August 2001
J2EE 1.3, J2SE 1.2
Addition of Filter
Servlet 2.2
August 1999
J2EE 1.2, J2SE 1.2
Becomes part of J2EE, introduced independent web applications in .war files
Servlet 2.1
November 1998
Unspecified
First official specification, added RequestDispatcher, ServletContext
Servlet 2.0
JDK 1.1
Part of Java Servlet Development Kit 2.0
Servlet 1.0
June 1997
[edit] Tags:Server,Web Server,Java Platform,Java,Api,War File,Edit,Sun Microsystems,Glassfish, | |
| Advantages over CGI | |
| 2>
The advantages of using servlets are their fast performance and ease of use combined with more power over traditional CGI (Common Gateway Interface). Traditional CGI scripts written in Java have a number of disadvantages when it comes to performance:
When an HTTP request is made, a new process is created for each call of the CGI script. This overhead of process creation can be very system-intensive, especially when the script does relatively fast operations. Thus, process creation will take more time than CGI script execution. Java servlets solve this, as a servlet is not a separate process. Each request to be handled by a servlet is handled by a separate Java thread within the Web server process, omitting separate process forking by the HTTP daemon.
Simultaneous CGI request causes the CGI script to be copied and loaded into memory as many times as there are requests. However, with servlets, there are the same amount of threads as requests, but there will only be one copy of the servlet class created in memory that stays there also between requests.
Only a single instance answers all requests concurrently. This reduces memory usage and makes the management of persistent data easy.
A servlet can be run by a servlet engine in a restrictive environment, called a sandbox. This is similar to an applet that runs in the sandbox of the Web browser. This makes a restrictive use of potentially harmful servlets possible.[2]
[edit] Tags:Class,Browser,Http,Cgi,Sandbox,Read, | |
| Life cycle of a servlet | |
| 3>
During initialization stage of the Servlet life cycle, the web container initializes the servlet instance by calling the init() method. The container passes an object implementing the ServletConfig interface via the init() method. This configuration object allows the servlet to access name-value initialization parameters from the web application.
After initialization, the servlet can service client requests. Each request is serviced in its own separate thread. The Web container calls the service() method of the servlet for every request. The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request. The developer of the servlet must provide an implementation for these methods. If a request for a method that is not implemented by the servlet is made, the method of the parent class is called, typically resulting in an error being returned to the requester.
Finally, the Web container calls the destroy() method that takes the servlet out of service. The destroy() method, like init(), is called only once in the lifecycle of a servlet.
Three methods are central to the life cycle of a servlet. These are init( ), service( ), and destroy( ). They are implemented by every servlet and are invoked at specific times by the server. Let us consider a typical user scenario to understand when these methods are called.
Assume that a user enters a Uniform Resource Locator (URL) to a web browser.
The browser then generates an HTTP request for this URL.
This request is then sent to the appropriate server.
The HTTP request is received by the web server.
The server maps this request to a particular servlet.
The servlet is dynamically retrieved and loaded into the address space of the server.
The server invokes the init() method of the servlet.
This method is invoked only when the servlet is first loaded into memory.
It is possible to pass initialization parameters to the servlet so it may configure itself.
The server invokes the service() method of the servlet.
This method is called to process the HTTP request.
You will see that it is possible for the servlet to read data that has been provided in the HTTP request.
It may also formulate an HTTP response for the client.
The servlet remains in the server’s address space and is available to process any other HTTP requests received from clients.
The service() method is called for each HTTP request.
The server may, at some point, decide to unload the servlet from its memory.
The algorithms by which this determination is made are specific to each server.
The server calls the destroy() method to relinquish any resources such as file handles that are allocated for the servlet; important data may be saved to a persistent store.
The memory allocated for the servlet and its objects can then be garbage collected.
[edit] Tags:Web Container, | |
| Example | |
| 3>
The following example servlet prints a "Hello world" HTML page.
Note that HttpServlet is a subclass of GenericServlet, an implementation of the Servlet interface.
The service() method dispatches requests to the methods doGet(), doPost(), doPut(), doDelete(), and so on; according to the HTTP request.
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletLifeCycleExample extends HttpServlet {
private int count;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
getServletContext().log("init() called");
count=0;
}
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
getServletContext().log("service() called");
count++;
response.getWriter().write("Incrementing the count: Count = "+count);
}
@Override
public void destroy() {
getServletContext().log("destroy() called");
}
}
[edit] Tags:Html, | |
| Usage | |
| 2>
Servlets are most often used to
process or store data that was submitted from an HTML form
provide dynamic content such as the results of a database query
manage state information that does not exist in the stateless HTTP protocol, such as filling the articles into the shopping cart of the appropriate customer.
[edit] Tags:Dynamic Content,State,Article, | |
| See also | |
| 2>
Java portal
JavaServer Pages compiler
Servers
Jetty
Apache Tomcat
JBoss
GlassFish
IBM WebSphere Application Server
[edit] Tags:Servers,Javaserver Pages,Java Portal,Javaserver Pages Compiler,Jetty,Apache Tomcat,Jboss,Ibm Websphere Application Server,Apache, | |
| References | |
| 2>
^ "servlet". http://www.webopedia.com/: WEBOPEDIA. http://www.webopedia.com/TERM/S/servlet.html. Retrieved 2011-04-27. "A small program that runs on a server. The term usually refers to a Java applet that runs within a Web server environment. This is analogous to a Java applet that runs within a Web browser environment."
^ a b c [1] 1.1 What is a servlet?
[edit] Tags:Java Applet, | |
| External links | |
| 2>
Sun's servlet tutorial
Beginning and intermediate servlet and JSP tutorials With source code
Sun's servlet product description
JSR
JSR 315 - Servlet 3.0
JSR 154 - Servlet 2.4 and 2.5
JSR 53 - Servlet 2.3
Java Servlet Technology Sun Servlet Archive (2.0/2.1)
New features added to Servlet 3.0
New features added to Servlet 2.5 at JavaWorld
Java Documentation of the Servlet 2.5 API
v
d
e
Java
Java platform
Java language · JVM · Micro Edition · Standard Edition · Enterprise Edition · Java Card
Sun technologies
Squawk · Java Development Kit · OpenJDK · Java virtual machine · JavaFX · Maxine VM
Platform technologies
Applets · Servlets · MIDlets · jsp · Web Start (jnlp)
Major third-party technologies
JRockit · GNU Classpath · Kaffe · TopLink · Apache Harmony · Apache Struts · Spring framework · Hibernate · JBoss application server · Tapestry · Jazelle
History
Java version history · Java Community Process · Sun Microsystems · Free Java implementations
Major programming languages
BeanShell · Clojure · Groovy · Oxygene · Java Tcl · JRuby · Jython · Processing · Rhino · Scala · more…
Java conferences
JavaOne
v
d
e
Web server interfaces
General
Common Gateway Interface (CGI)
Simple CGI
FastCGI
Technology specific
ISAPI
Java Servlet
NSAPI
AJP
Python WSGI
Ruby Rack
JavaScript JSGI
Perl PSGI
Lua WSAPI
Apache modules
mod_jk
mod_lisp
mod_parrot
mod_perl
mod_php
mod_python
mod_wsgi
mod_ruby
Retrieved from "http://en.wikipedia.org/w/index.php?title=Java_Servlet&oldid=473847845"
Categories: Java enterprise platformJava platformJava specification requestsHidden categories: Wikipedia introduction cleanup from January 2012All pages needing cleanup
Personal tools
Log in / create account
Namespaces
Article
Talk
Variants
Views
Read
Edit
View history
Actions
Search
Navigation
Main page
Contents
Featured content
Current events
Random article
Donate to Wikipedia
Interaction
Help
About Wikipedia
Community portal
Recent changes
Contact Wikipedia
Toolbox
What links here
Related changes
Upload file
Special pages
Permanent link
Cite this page
Print/export
Create a bookDownload as PDFPrintable version
Languages
العربية
Български
Català
Dansk
Deutsch
Español
Esperanto
فارسی
Français
한국어
Italiano
עברית
Lietuvių
Magyar
Nederlands
日本語
Polski
Português
Română
Русский
Српски / Srpski
Svenska
Türkçe
Українська
Tiếng Việt
中文
This page was last modified on 29 January 2012 at 12:59.
Text is available under the Creative Commons Attribution-ShareAlike License;
additional terms may apply.
See Terms of use for details.
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.Contact us
Privacy policy
About Wikipedia
Disclaimers
Mobile view
if ( window.isMSIE55 ) fixalpha();
if ( window.mediaWiki ) {
mw.loader.load(["mediawiki.user", "mediawiki.util", "mediawiki.page.ready", "mediawiki.legacy.wikibits", "mediawiki.legacy.ajax", "mediawiki.legacy.mwsuggest", "ext.gadget.wmfFR2011Style", "ext.vector.collapsibleNav", "ext.vector.collapsibleTabs", "ext.vector.editWarning", "ext.vector.simpleSearch", "ext.UserBuckets", "ext.articleFeedback.startup", "ext.articleFeedbackv5.startup", "ext.markAsHelpful"]);
}
if ( window.mediaWiki ) {
mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":1,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"highlightbroken":1,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":false,"showjumplinks":1,"shownumberswatching":1,"showtoc":1,"showtoolbar":1,"skin":"vector","stubthreshold":0,"thumbsize":4,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":1,"watchdefault":0,"watchdeletion":0,"watchlistdays":3,"watchlisthideanons":0,
"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"flaggedrevssimpleui":1,"flaggedrevsstable":0,"flaggedrevseditdiffs":true,"flaggedrevsviewdiffs":false,"vector-simplesearch":1,"useeditwarning":1,"vector-collapsiblenav":1,"usebetatoolbar":1,"usebetatoolbar-cgd":1,"wikilove-enabled":1,"variant":"en","language":"en","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"searchNs100":false,"searchNs101":false,"searchNs108":false,"searchNs109":false,"gadget-wmfFR2011Style":1});;mw.user.tokens.set({"editToken":"+\\","watchToken":false});;mw.loader.state({"user.options":"ready","user.tokens":"ready"});
/* cache key: enwiki:resourceloader:filter:minify-js:4:b41a86ec4e0fe8329bc3ce917e792339 */
}
Tags:Java Card,Maxine Vm,Web Start (jnlp),Jazelle,Free Java Implementations,More…,Javaone,Common Gateway Interface (cgi),Simple Cgi,Fastcgi,Isapi,Nsapi,Ajp,Python Wsgi,Ruby Rack,Javascript Jsgi,Perl Psgi,Mod_jk,Mod_lisp,Mod_parrot,Mod_perl,Mod_php,Mod_python,Mod_wsgi,Mod_ruby,Categories,Java Enterprise Platform, | |
zote monety click here click here click here click here |