Sie sind auf Seite 1von 1

Java Servlet

From Wikipedia, the free encyclopedia

Life of a JSP file.


A servlet is a Java programming language class used to extend the capabilities o
f servers that host applications accessed via a request-response programming mod
el. Although servlets can respond to any type of request, they are commonly used
to extend the applications hosted by Web servers. Actually, it is a Java Applet
that runs on a server instead of a browser.[1]
A Servlet is a Java class in Java EE that conforms to the Java Servlet API, a pr
otocol by which a Java class may respond to requests. They are not tied to a spe
cific client-server protocol, but are most often used with the HTTP protocol. Th
erefore, the word "Servlet" is often used in the meaning of "HTTP Servlet".[2] T
hus, a software developer may use a servlet to add dynamic content to a Web serv
er using the Java platform. The generated content is commonly HTML, but may be o
ther data such as XML. Servlets are the Java counterpart to non-Java dynamic Web
content technologies such as CGI and ASP.NET. Servlets can maintain state in se
ssion variables across many server transactions by using HTTP cookies, or URL re
writing.
To deploy and run, the Apache Tomcat Server may be used. It is an open source se
rvlet container developed by the Apache Software Foundation (ASF). Tomcat implem
ents the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Mic
rosystems, and provides a "pure Java" HTTP web server environment for Java code
to run.
The servlet API, contained in the Java package hierarchy javax.servlet, defines
the expected interactions of a Web container and a servlet.[2] A Web container i
s essentially the component of a Web server that interacts with the servlets. Th
e Web container is responsible for managing the lifecycle of servlets, mapping a
URL to a particular servlet and ensuring that the URL requester has the correct
access rights.
A Servlet is an object that receives a request and generates a response based on
that request. The basic servlet package defines Java objects to represent servl
et requests and responses, as well as objects to reflect the servlet's configura
tion parameters and execution environment. The package javax.servlet.http define
s HTTP-specific subclasses of the generic servlet elements, including session ma
nagement objects that track multiple requests and responses between the Web serv
er and a client. Servlets may be packaged in a WAR file as a Web application.
Servlets can be generated automatically from JavaServer Pages (JSP) by the JavaS
erver Pages compiler. The difference between Servlets and JSP is that Servlets t
ypically embed HTML inside Java code, while JSPs embed Java code in HTML. While
the direct usage of Servlets to generate HTML (as shown in the example below) is
relatively rare nowadays, the higher level MVC web framework in Java EE (JSF) s
till explicitly uses the Servlet technology for the low level request/response h
andling via the FacesServlet. A somewhat older usage is to use servlets in conju
nction with JSPs in a pattern called "Model 2", which is a flavour of the model-
view-controller pattern.

Das könnte Ihnen auch gefallen