39
Java Servelets Java Servelets

Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Embed Size (px)

Citation preview

Page 1: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Java ServeletsJava Servelets

Page 2: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

A servlet is a server side software A servlet is a server side software component, written in java that component, written in java that dynamically extends the functionality dynamically extends the functionality of a server.of a server.

Unlike applets servlets don’t display Unlike applets servlets don’t display GUI.GUI.

It works behind the scene on server It works behind the scene on server and results of servlet’s processing are and results of servlet’s processing are returned to the client.returned to the client.

Page 3: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

What Is a Servlet? What Is a Servlet?

A A servletservlet is a Java programming language is a Java programming language class used to extend the capabilities of class used to extend the capabilities of servers that host applications accessed via a servers that host applications accessed via a request-response programming model. request-response programming model.

Although servlets can respond to any type of Although servlets can respond to any type of request, they are commonly used to extend request, they are commonly used to extend the applications hosted by Web servers.the applications hosted by Web servers.

For such applications, Java Servlet For such applications, Java Servlet technology defines HTTP-specific servlet technology defines HTTP-specific servlet classes. classes.

Page 4: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

A servlet is an instance of a class that A servlet is an instance of a class that implements the java.servlet.Servlet interface.implements the java.servlet.Servlet interface.

The The javax.servletjavax.servlet and and javax.servlet.httpjavax.servlet.http packages provide interfaces and classes for packages provide interfaces and classes for writing servlets.writing servlets.

All servlets must implement the All servlets must implement the ServletServlet interface, which defines life-cycle methods. interface, which defines life-cycle methods.

When implementing a generic service, you can When implementing a generic service, you can use or extend the use or extend the GenericServletGenericServlet class provided class provided with the Java Servlet API. with the Java Servlet API.

The The HttpServletHttpServlet class provides methods, such class provides methods, such as doGet and doPost, for handling HTTP-specific as doGet and doPost, for handling HTTP-specific services. services.

Page 5: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

javax.servlet.GenericServletjavax.servlet.GenericServletSignature: public abstract class GenericServlet extends Signature: public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.lang.Object implements Servlet, ServletConfig, java.io.Serializablejava.io.Serializable

GenericServlet defines a generic, protocol-independent GenericServlet defines a generic, protocol-independent servlet. servlet.

GenericServlet gives a blueprint and makes writing servlet GenericServlet gives a blueprint and makes writing servlet easier. easier.

GenericServlet provides simple versions of the lifecycle GenericServlet provides simple versions of the lifecycle methods init and destroy and of the methods in the methods init and destroy and of the methods in the ServletConfig interface. ServletConfig interface.

GenericServlet implements the log method, declared in the GenericServlet implements the log method, declared in the ServletContext interface. ServletContext interface.

To write a generic servlet, it is sufficient to override the To write a generic servlet, it is sufficient to override the abstract service method. abstract service method.

Page 6: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

javax.servlet.http.HttpServletjavax.servlet.http.HttpServletSignature: public abstract class Signature: public abstract class HttpServlet extends GenericServlet HttpServlet extends GenericServlet implements java.io.Serializableimplements java.io.Serializable

HttpServlet defines a HTTP protocol HttpServlet defines a HTTP protocol specific servlet. specific servlet.

HttpServlet gives a blueprint for Http HttpServlet gives a blueprint for Http servlet and makes writing them easier. servlet and makes writing them easier.

HttpServlet extends the GenericServlet HttpServlet extends the GenericServlet and hence inherits the properties and hence inherits the properties GenericServlet. GenericServlet.

Page 7: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Advantages Advantages Capable of running in same process space as the Capable of running in same process space as the

web server.web server. Compiled.Compiled. Crash resistantCrash resistant Cross platformCross platform DurableDurable Dynamically loaded across the networkDynamically loaded across the network ExtensibleExtensible MultithreadedMultithreaded Protocol independentProtocol independent Written in javaWritten in java

Page 8: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

FunctionsFunctions

Dynamically build and return an Dynamically build and return an HTML file based on client request.HTML file based on client request.

Process user input of HTML Form and Process user input of HTML Form and return appropriate response.return appropriate response.

Facilitate communication among Facilitate communication among many clients.many clients.

Interact with server resources like Interact with server resources like database, other application.database, other application.

Multiplayer games.Multiplayer games.

Page 9: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

HTTP Request StructureHTTP Request Structure

It is a stateless protocol.It is a stateless protocol. Server does not have the overhead of Server does not have the overhead of

tracking client connections.tracking client connections. HTTP transactions are either a request HTTP transactions are either a request

or response.or response. Servlet can overcome the stateless Servlet can overcome the stateless

nature of HTTP by tracking client state nature of HTTP by tracking client state using session information stored in using session information stored in URL, hidden fields or cookies.URL, hidden fields or cookies.

Page 10: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

3 parts of HTTP transactions3 parts of HTTP transactions

A single request or response lineA single request or response line– <HTTP Method>/<document address>HTTP/ <HTTP Method>/<document address>HTTP/

<Version No> e.g.<Version No> e.g.– GET /index.html HTTP/1.1GET /index.html HTTP/1.1– Response line contains an HTTP status code.Response line contains an HTTP status code.HTTP/1.1 200 OKHTTP/1.1 200 OKDate:……………………….GMTDate:……………………….GMTServer:Server:Last-modified:Last-modified:Content-type: text/htmlContent-type: text/htmlContent-length:….bytesContent-length:….bytes

Page 11: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

501 error is generated by the server 501 error is generated by the server when a servlet is sent an HTTP when a servlet is sent an HTTP request that it does not handle. E.g. request that it does not handle. E.g. if you write your servlet to handle if you write your servlet to handle only GET requests, but it receives a only GET requests, but it receives a POST request, a 501 status will POST request, a 501 status will return.return.

Page 12: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

HTTP headers HTTP headers – A set of fields used to exchange information A set of fields used to exchange information

between client and server.between client and server.– Client uses the headers to tell the server about Client uses the headers to tell the server about

its configuration and the document types it’ll its configuration and the document types it’ll accept.accept.

– Server uses the header to return information Server uses the header to return information about the requested document.about the requested document.

HTTP BodyHTTP Body– Optionally used by client to send any additional Optionally used by client to send any additional

information.information.– The server uses the body to return the The server uses the body to return the

requested document.requested document.

Page 13: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

HTTP MethodsHTTP Methods

GET is used to request information from GET is used to request information from server.server.

POST is used to send data to the server.POST is used to send data to the server. GET can also be used to pass information in GET can also be used to pass information in

form of query string in URL and POST can be form of query string in URL and POST can be used for request.used for request.

Information sent as GET is visible to the Information sent as GET is visible to the client and append at URL.client and append at URL.

POST sends data directly after the header, in POST sends data directly after the header, in body of message and doesn’t append at URL.body of message and doesn’t append at URL.

Page 14: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

HEADHEAD– If client wants information about a document If client wants information about a document

but does not want the document to be returned.but does not want the document to be returned. PUTPUT

– Requests to server to store the body at a Requests to server to store the body at a specified URLspecified URL

DELETEDELETE– Requests the removal of data at URLRequests the removal of data at URL

TRACETRACE– Used for debugging. The HTTP body is simply Used for debugging. The HTTP body is simply

returned by the server.returned by the server.

Page 15: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Servlet EnvironementServlet Environement The web server provides support for The web server provides support for

servlets with extensions called servlet servlets with extensions called servlet containers.containers.

Servlet Containers Functions:Servlet Containers Functions:– Network services over which request / response Network services over which request / response

are sent.are sent.– Registers the servlet against one or more URLRegisters the servlet against one or more URL– Manage servlet life cycleManage servlet life cycle– Decodes MIME (Multipurpose Internet Mail Decodes MIME (Multipurpose Internet Mail

Extensions) requestsExtensions) requests– Constructs MIME responseConstructs MIME response– Support HTTP protocolSupport HTTP protocol– Enforce security restrictions on environment.Enforce security restrictions on environment.

Page 16: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Advantage of Servlets Over Advantage of Servlets Over CGICGI

Java servlets are more efficient, easier to use, more powerful, more Java servlets are more efficient, easier to use, more powerful, more portable, and cheaper than traditional CGI and than many alternative CGI-portable, and cheaper than traditional CGI and than many alternative CGI-like technologies. (More importantly, servlet developers get paid more than like technologies. (More importantly, servlet developers get paid more than Perl programmers :-). Perl programmers :-).

Efficient.Efficient. – With traditional CGI, a new process is started for each HTTP request. With traditional CGI, a new process is started for each HTTP request. – If the CGI program does a relatively fast operation, the overhead of starting the If the CGI program does a relatively fast operation, the overhead of starting the

process can dominate the execution time. process can dominate the execution time. – With servlets, the Java Virtual Machine stays up, and each request is handled by With servlets, the Java Virtual Machine stays up, and each request is handled by

a lightweight Java thread, not a heavyweight operating system process. a lightweight Java thread, not a heavyweight operating system process. – Similarly, in traditional CGI, if there are Similarly, in traditional CGI, if there are NN simultaneous request to the same CGI simultaneous request to the same CGI

program, then the code for the CGI program is loaded into memory N times. program, then the code for the CGI program is loaded into memory N times. – With servlets, however, there are With servlets, however, there are NN threads but only a single copy of the servlet threads but only a single copy of the servlet

class. Servlets also have more alternatives than do regular CGI programs for class. Servlets also have more alternatives than do regular CGI programs for optimizations such as caching previous computations, keeping database optimizations such as caching previous computations, keeping database connections open, and the like. connections open, and the like.

Convenient.Convenient. – You already know Java. You already know Java. – Why learn Perl too? Besides the convenience of being able to use a familiar Why learn Perl too? Besides the convenience of being able to use a familiar

language, servlets have an extensive infrastructure for automatically parsing language, servlets have an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions, and many other such utilities. cookies, tracking sessions, and many other such utilities.

Page 17: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Powerful.Powerful. – Java servlets let you easily do several things that are difficult or impossible with Java servlets let you easily do several things that are difficult or impossible with

regular CGI. regular CGI. – For one thing, servlets can talk directly to the Web server (regular CGI programs For one thing, servlets can talk directly to the Web server (regular CGI programs

can't). can't). – This simplifies operations that need to look up images and other data stored in This simplifies operations that need to look up images and other data stored in

standard places. standard places. – Servlets can also share data among each other, making useful things like database Servlets can also share data among each other, making useful things like database

connection pools easy to implement. connection pools easy to implement. – They can also maintain information from request to request, simplifying things like They can also maintain information from request to request, simplifying things like

session tracking and caching of previous computations. session tracking and caching of previous computations. Portable.Portable.

– Servlets are written in Java and follow a well-standardized API. Servlets are written in Java and follow a well-standardized API. – Consequently, servlets written for, say I-Planet Enterprise Server can run virtually Consequently, servlets written for, say I-Planet Enterprise Server can run virtually

unchanged on Apache, Microsoft IIS, or WebStar. unchanged on Apache, Microsoft IIS, or WebStar. – Servlets are supported directly or via a plugin on almost every major Web server. Servlets are supported directly or via a plugin on almost every major Web server.

Inexpensive.Inexpensive. – There are a number of free or very inexpensive Web servers available that are good There are a number of free or very inexpensive Web servers available that are good

for "personal" use or low-volume Web sites. for "personal" use or low-volume Web sites. – However, with the major exception of Apache, which is free, most commercial-However, with the major exception of Apache, which is free, most commercial-

quality Web servers are relatively expensive. quality Web servers are relatively expensive. – Nevertheless, once you have a Web server, no matter the cost of that server, adding Nevertheless, once you have a Web server, no matter the cost of that server, adding

servlet support to it (if it doesn't come preconfigured to support servlets) is generally servlet support to it (if it doesn't come preconfigured to support servlets) is generally free or cheapfree or cheap

Page 18: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Servlet APIServlet API It doesn’t run as an application rather it is loaded in It doesn’t run as an application rather it is loaded in

memory and as instance is created.memory and as instance is created. When a servlet instance is created its init() is When a servlet instance is created its init() is

called.called. Servlets are required to respond to new Servlets are required to respond to new

connections to the server.connections to the server. When a new connection is detected, a call is made When a new connection is detected, a call is made

to the service() of the servlet.to the service() of the servlet. service() takes two parameters defined by interface service() takes two parameters defined by interface

type called ServletRequest and ServletResponse.type called ServletRequest and ServletResponse. Servlet class is abstract because service() is Servlet class is abstract because service() is

defined not implemented; so to implement a defined not implemented; so to implement a servlet, it is necessary to override this method.servlet, it is necessary to override this method.

Page 19: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Servlet class is not protocol specific.Servlet class is not protocol specific. A subclass of Servlet class, the HttpServlet A subclass of Servlet class, the HttpServlet

class is provided to handle http protocol.class is provided to handle http protocol. Two interfaces are defined for use with Two interfaces are defined for use with

HttpServlet classHttpServlet class– HttpServletRequestHttpServletRequest– HttpServletResponseHttpServletResponse

These extend the ServletRequest & These extend the ServletRequest & ServletResponse.ServletResponse.

Page 20: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Life Cycle of ServletLife Cycle of Servlet

Servlet life cycle is defined by Servlet life cycle is defined by javax.servlet.Servlet inteface.javax.servlet.Servlet inteface.

All servlets must implement All servlets must implement javax.servlet.Servlet interface to run javax.servlet.Servlet interface to run in a servlet engine.in a servlet engine.

Page 21: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Servlet Class

Instantiation & loadingServlet engine can

instantiate more than one servlet instance

Initializationinit(ServletConfig conf)

Readyservice()

A service() executes for each servlet instance

Destructiondestroy()

Garbage CollectionServer no longer

has a reference to the object

Page 22: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

ServletServlet

init()init() destroy()destroy() getServletConfig()getServletConfig() getServletInfo()getServletInfo() service()service()

Page 23: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

GenericServletGenericServlet init()init() distroy()distroy() log()log() getServletConfig()getServletConfig() getServletContext()getServletContext() getInitParameter()getInitParameter() getInitParameterNames()getInitParameterNames() getServletInfo()getServletInfo() getServletName()getServletName() service()service()

Page 24: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

HTTPServletHTTPServlet

doGet()doGet() doPost()doPost() doHead()doHead() doDelete()doDelete() doOptions()doOptions() doPut()doPut() doTrace()doTrace() getLastModified()getLastModified() service()service()

Page 25: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Creating servletsCreating servlets

protected void protected void service(HttpServletRequest req, service(HttpServletRequest req, HttpServletResponse resp) throws HttpServletResponse resp) throws ServletException, IOExceptionServletException, IOException

Standard HTTP requests like Get and Standard HTTP requests like Get and Post are supported by doGet() and Post are supported by doGet() and doPost().doPost().

Page 26: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

HttpServletRequestHttpServletRequest

getMethod()getMethod()– Returns get/post with which request was made.Returns get/post with which request was made.

getQueryString()getQueryString() getRemoteUser()getRemoteUser() getRequestSessionId()getRequestSessionId() getSession(boolean)getSession(boolean)

– If FALSE returns current valid session otherwise If FALSE returns current valid session otherwise creates a new session.creates a new session.

isRequestedSessionIdValid()isRequestedSessionIdValid() getCookies()getCookies()

Page 27: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

HttpServletResponseHttpServletResponse

addCookie(Cookie)addCookie(Cookie)– Add cookie to responseAdd cookie to response

encodeUrl(String)encodeUrl(String) sendRedirect(String)sendRedirect(String) sendError(int)sendError(int)

Page 28: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Servlet ContextServlet Context

The javax.servlet.ServletContext The javax.servlet.ServletContext interface provides a set of methods interface provides a set of methods that the servlet can use to that the servlet can use to communicate with the web server.communicate with the web server.

The ServletContext object is The ServletContext object is contained within contained within javax.servlet.ServletConfig Object javax.servlet.ServletConfig Object which is provided to the servlet when which is provided to the servlet when it is initialized.it is initialized.

Page 29: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Functions of ServletContext Functions of ServletContext ObjectObject

Set and store attributes that other servlets Set and store attributes that other servlets in the context can access.in the context can access.

Log eventsLog events Obtain URL references to resources.Obtain URL references to resources. Get values assigned to initialization Get values assigned to initialization

parameters.parameters. Get the MIME types of files.Get the MIME types of files. Obtain information about the servlet Obtain information about the servlet

container such as its name and version.container such as its name and version. A servlet context is associated with a web A servlet context is associated with a web

application and shared by all the servlets application and shared by all the servlets within that application.within that application.

Page 30: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Web Application Files and Web Application Files and Directory StructureDirectory Structure

Each web application has a root called the Each web application has a root called the context path.context path.

No two applications, in the same Web Server, can No two applications, in the same Web Server, can have the same context path because this would have the same context path because this would cause URL conflicts.cause URL conflicts.

Document root is a special directory called WEB-Document root is a special directory called WEB-INF.INF.

Contents of WEB-INF are-Contents of WEB-INF are-– Web.xml file web application deployment descriptorWeb.xml file web application deployment descriptor– /classes directory /classes directory – /lib directory storage area for JAR file/lib directory storage area for JAR file– /tags directory used to store tag libraries/tags directory used to store tag libraries

Page 31: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

There may be META-INF directory that There may be META-INF directory that contains implementation-specific contains implementation-specific deployment descriptor and WSDL (Web deployment descriptor and WSDL (Web Service Definition Language) directory.Service Definition Language) directory.

/META-INF/MANIFEST.MF/META-INF/MANIFEST.MF /WEB-INF/classes/HTMLPage.class/WEB-INF/classes/HTMLPage.class /WEB-INF/classes/VerifyData.class/WEB-INF/classes/VerifyData.class /WEB-INF/Web.xml/WEB-INF/Web.xml /WEB-INF/sun-Web.xml/WEB-INF/sun-Web.xml /index.html/index.html

Page 32: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Handling ErrorsHandling Errors HTTP ErrorsHTTP Errors

– XML error-page tag can be usedXML error-page tag can be used<error-page><error-page>

<error-code>404</error-code><error-code>404</error-code><location>/examples/error404.html</location><location>/examples/error404.html</location>

</error-page></error-page>– On error, the servlet can use either of the following On error, the servlet can use either of the following

method to set HTTP status code:method to set HTTP status code:public void HttpServletResponse.sendError(int sc)public void HttpServletResponse.sendError(int sc)public void HttpServletResponse.sendError(int sc,String public void HttpServletResponse.sendError(int sc,String msg)msg)

– On error servlet can be redirected to another URLOn error servlet can be redirected to another URL– HttpServletResponse.sendRedirect(String location)HttpServletResponse.sendRedirect(String location)

Page 33: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Servlet ExceptionsServlet Exceptions

Catch all servlet generated exceptions in Catch all servlet generated exceptions in servlet and take actions accordingly.servlet and take actions accordingly.

When a fatal error is generated an error When a fatal error is generated an error message can be displayedmessage can be displayedCatch(RemoteException e){Catch(RemoteException e){Res.sendError(503,”Internal Error”);Res.sendError(503,”Internal Error”);Res.sendRedirect(“/example/ReportErrorPage”);Res.sendRedirect(“/example/ReportErrorPage”);}}– During initialization or while handling requests During initialization or while handling requests

the servlet instance can throw an the servlet instance can throw an UnavailableException or ServletException.UnavailableException or ServletException.

Page 34: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Cookie ClassCookie Class Cookie used for session management with Cookie used for session management with

HTTP and HTTPS.HTTP and HTTPS. Used to get browsers to hold small data Used to get browsers to hold small data

associated with user’s browsing.associated with user’s browsing. Cookies are named and have single value.Cookies are named and have single value. Assigned by the servers using fields added Assigned by the servers using fields added

to HTTP response headers.to HTTP response headers. Cookies are saved one at a time into HTTP Cookies are saved one at a time into HTTP

response headers using response headers using javax.servlet.http.HttpServletResponse.adjavax.servlet.http.HttpServletResponse.addCookie().dCookie().

Page 35: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Web browsers are expected to Web browsers are expected to support 20 cookies per host of at least support 20 cookies per host of at least 4KB each.4KB each.

HTTP request fields are retrieved HTTP request fields are retrieved using using javax.servlet.http.HttpServletRequest.javax.servlet.http.HttpServletRequest.getCookie().getCookie().

This returns all cookies found in This returns all cookies found in request.request.

Page 36: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Cookie ClassCookie Class

Cookie(String name,String value)Cookie(String name,String value) setDomain(String)setDomain(String) getDomain()getDomain() setMaxAge(int)setMaxAge(int)

– Age in sec; 0 to deleteAge in sec; 0 to delete getMaxAge()getMaxAge() setValue(String)setValue(String) getValue()getValue() getName()getName()

Page 37: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

ExampleExample FirstServlet.htmlFirstServlet.html FirstServlet.javaFirstServlet.java STEPSSTEPS Set Set

classpath=c:/jsdk2.0/lib/jsdk.jar;C:/jsdk2.0/srclasspath=c:/jsdk2.0/lib/jsdk.jar;C:/jsdk2.0/srcc

Compile .java fileCompile .java file– .class file should be in example directory.class file should be in example directory

Run servletrunnerRun servletrunner Run FirstServlet.html in browserRun FirstServlet.html in browser

– C:\JSDK2.0\examples\FirstServlet.htmlC:\JSDK2.0\examples\FirstServlet.html

Page 38: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

Survey.htmlSurvey.html Survey.javaSurvey.java

Page 39: Java Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a

QuestionsQuestions What are two methods of HTTP to send What are two methods of HTTP to send

requests to web server? Which should you use requests to web server? Which should you use to send large amounts of information to the to send large amounts of information to the server?server?

What are the main uses of ServletContext What are the main uses of ServletContext Object?Object?

What are the differences between Generic What are the differences between Generic Servlet and Servlet?Servlet and Servlet?

What is pre initialization and lazy initialization What is pre initialization and lazy initialization of servlet?of servlet?

Write short notes on Error handling of Servlet.Write short notes on Error handling of Servlet.