You are on page 1of 2

CHAPTER_1

 Functions of servlet:

-Read explicit data sent by the client.

-Read implicit data from http request data sent by browser

-Generate results

-Send explicit data to the client

-send implicit http response data to the client

 Servlet is for processing the request and jsp s for presentation.


 Doget{

//Use request to read incoming http headers (cookies) and query data from html form

//Use response to to specify http response status

//code and headers

//use out to send content to the browser

 3 steps 2 be followed to generate html using servlet:

1.Tell the browser that you’re sending it HTML. –This can be accomplished by setting Http Content-Type

i.e response.setContentType(“text/html”)

2. Modify the println statements to build a legal Web page.

3. Check your HTML with a formal syntax validator.

 Set response headers before actually returning any of the content with the PrintWriter because http
response consists of headers.
 You must set the content type before transmitting the actual document.
 <!DOCTYPE ...>----------------This tag is used to know which html version is being used

 JAVA SERVER PAGES:


Inconvenience of generating HTML programmatically is one of the main problems addressed by
JavaServer Pages.
Servlet println statements does not support full range of HTML attributes like class and id for style
sheets

SERVLET LIFE CYCLE:


When the servlet is first created, its init method is invoked, so init is where you put one-time setup
code. After this, each user request results in a thread that calls the service method of the previously
created instance. Multiple concurrent requests normally result in multiple threads calling service
simultaneously, although your servlet can implement a special interface (SingleThreadModel) that
stipulates that only a single thread is permitted to run at any one time. The service method then
calls doGet, doPost, or another doXxx method, depending on the type of HTTP request it received.
Finally, if the server decides to unload a servlet, it first calls the servlet’s destroy method.

You might also like