Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



what is servlet


Posted Date: 17 Mar 2008    Resource Type: Articles/Knowledge Sharing    Category: General

Posted By: Aparanjitha       Member Level: Gold
Rating:     Points: 5



Web Components

•Servlets

•Java Server Pages (JSP)

•Tags and Tag Libraries

What’s a Servlet?

•Java’s answer to CGI programming

•Program runs on Web server and builds pages on the fly

•When would you use servlets?

–Data changes frequently e.g. weather-reports

–Page uses information from databases e.g. on-line stores

–Page is based on user-submitted data e.g search engines

–Data changes frequently e.g. weather-reports

–Page uses information from databases e.g. on-line stores

–Page is based on user-submitted data e.g search engines

Servlet Class Hierarchy

•javax.servlet.Servlet

–Defines methods that all servlets must implement

•init()

•service()

•destroy()

•javax.servlet.GenericServlet

–Defines a generic, protocol-independent servlet

•javax.servlet.http.HttpServlet

–To write an HTTP servlet for use on the Web

•doGet()

•doPost()

•javax.servlet.ServletConfig

–A servlet configuration object

–Passes information to a servlet during initialization

•Servlet.getServletConfig()

•javax.servlet.ServletContext

–To communicate with the servlet container

–Contained within the ServletConfig object

•ServletConfig.getServletContext()

•javax.servlet.ServletRequest

–Provides client request information to a servlet

•javax.servlet.ServletResponse

–Sending a response to the client

Basic Servlet Structure

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class Hello World extends HttpServlet {

// Handle get request

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// request – access incoming HTTP headers and HTML form data

// response - specify the HTTP response line and headers

// (e.g. specifying the content type, setting cookies).

PrintWriter out = response.getWriter(); //out - send content to browser

out.println("Hello World");


}

}


Servlet Life Cycle

•Loading and Instantiation

•Initialization

•Request Handling

•End of Service


Session Tracking

•Typical scenario – shopping cart in online store

•Necessary because HTTP is a "stateless" protocol

•Session Tracking API allows you to

–look up session object associated with current request

–create a new session object when necessary

–look up information associated with a session

–store information in a session

–discard completed or abandoned sessions


Session Tracking API - I

•Looking up a session object

–HttpSession session = request.getSession(true);

–Pass true to create a new session if one does not exist

•Associating information with session

–session.setAttribute(“user”,request.getParameter(“name”))

–Session attributes can be of any type

•Looking up session information

–String name = (String) session.getAttribute(“user”)


Session Tracking API - II

•getId : –the unique identifier generated for the session

•isNew : –true if the client (browser) has never seen the session

•getCreationTime : –time in milliseconds since session was made

•getLastAccessedTime : –time in milliseconds since the session was last sent from client

•getMaxInactiveInterval : –# of seconds session should go without access before being invalidated . –negative value indicates that session should never timeout


Javax.Servlet Interface Classes

Servlet Genericservlet

ServletRequest ServletInputStream

ServletResponce ServletOutputStream

ServletConfig ServletException

ServletContext UnavailableException

SingleThreadModel -

Javax.Servlet.Http Classes

HttpServletRequest Cookie

HttpServletResponse HttpServlet

HttpSession HttpSessionBindingEvent

HttpSessionContext HttpUtils

HttpSessionBindingListener -

Exceptions

ServletException

UnavailableException





Responses

Author: Deepu    19 Mar 2008Member Level: Diamond   Points : 2
Good work Aparanjitha.Keep going with your postings.You have done a great home work.good job keep it up.


Author: Aparanjitha    19 Mar 2008Member Level: Gold   Points : 3
thanks for ur suggestions and encouragement keep on reading my resoucres and give me some more advises . As you said before i want to gain knowledge in all fields and place resources that will be help ful to non cs . Thank you



Author: Deepu    19 Mar 2008Member Level: Diamond   Points : 3
Sure,I will go on reading your postings.If you go on accepting my advices i will give more advises for your development in the site.Keep going.But just keep in mind that your postings are going to be read by hundreds of people throughout the world.


Author: Aparanjitha    19 Mar 2008Member Level: Gold   Points : 2
thnx for your reply to my msg. i mine it that my postings will be read by hundreds of people . so im sure that i will place good resources


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: java Q & A on JDBC
Previous Resource: History of Obesity
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources

Watch TV Channels



Contact Us    Editors    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.