Professional Documents
Culture Documents
CHAPTER 6 ~ SERVLET
3 Name the class that includes the getSession() 18 By default, how long does a cookie last?
method
HttpSession By default, a newly created cookie persists until
the browser exits.
6 A Deployement descriptor
describes_________________ 20 By default, Tomcat runs on port
web component settings ___________.
8080
45 HTTP servlet uses methods 80 Name the interface which is used to get
like__________________. initialization parameters for Servlet
doPost(),doGet() ServletConfig
52 In Http request method which is non- 81 Name the location of compiled class files
idempotent? within a jar file?
POST method /WEB-INF/classes
57 In which file do we define a servlet mapping? 82 Name the method defined in the
HttpServletResponse class that may be used to
web.xml set the content type.
setContentType
59 In which phase of JSP life cycle ,JSP page
turns into servlet?
JSP Compilation 84 Parameters are present in URL while
using__________method
doGet()
62 javax.servlet package does not contain
following class or interface.
HttpServlet 89 The doGet() Extracts values of the parameter
type and number by using ___________
request.getParameter()
68 JSP includes a mechanism for defining
............................... or custom tags
dynamic attributes 91 The getSession() method with its parameter
[getSession(true)]. It will return the appropriate
session object when ____
74 Life cycle of a JSP page consist of following
steps. the session is existing
Translation,compilation,Loading and
initialization,Request Handling,Destroy
99 The major difference between servlet and
CGI is
78 Name the http method that sends the same Servlets are thread based and CGI is process
response as the request. based
TRACE method
javax.servet.http
149 Which method is used to extract cookies
from a request?
111 To get the servlet environment information getCookies()
<%@ page ... %> 221 All the ___________ data is kept at the
application server ___________ data is kept at
the web server?
191 ________________method is secure. dynamic, static
doPost()
(HttpServletRequest req & HttpServletResponse 253 Choose the correct sequence steps for
res) running the servlet
• Write the servlet source code. We need to
204 1. Find out correct syntax of service() import the javax.servlet package and the
method of servlet class javax.servlet.http package in your source file.
void service(ServletRequest req, • Compile your source code.
ServletResponse res)
• Create a deployment descriptor.
• Run Tomcat.
205 1. Select correct scopes into JSP
• Call your servlet from a web browser.
page, request, session, application
AJP – 22517
CHAPTER 6 ~ SERVLET
Servlet filter
341 getSession(true) method will return
appropriate session object if……
323 Find the Syntactally Correct Statement the session is existing
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException 342 getWriter method is accessed as
___________
response.getWriter()
330 Following statement means: HttpSession
getSession( )
It will return existing session object, If not it will 360 Identify the correct sequence in Lifecycle of
create a new sesssion. JSP
Compile, Initialize, Execute, Destroy
331 For a given ServletResponse response, 366 In a URL query string, the parameter name
which retrieve an object for writing text data? and value are associated using the ____ symbol.
response.getWriter() E
=
397 In which folder we have to save java file for 464 The getAttribute(String attr) returns
servlet? Returns value of the server attribute
Classes
485 To get the servlet environment information? 535 Which classes are present in
ServletConfig object is used. javax.servlet.http package?
HttpServlet Cookie
514 What the ServletContainer does? 576 Which of these statements are false about
Provides the Runtime environment for servlets. GenericServlet?
Genric Servlet extends HttpServlet and override
doGet() method
528 When using HTML forms which of the
folowing is true for POST method
POST method sends data in the body of the 578 Which retrieves all cookies sent in a given
request HttpServletRequest request?
request.getCookies()
534 Which class provides stream to read binary 602 Apache Tomcat is a ________.
data such as image etc. from the request object? Web server that is capable of running Java
ServltInputStream programs.
AJP – 22517
CHAPTER 6 ~ SERVLET
• Servlets are the java programs that basically runs on the severs.
• It is managed by the Servlet container.
• Working of Servlet.
• Client requests servlets via web browser.
• Request is sent to web server.
• Server finds requested servlet.
• Servlet gathers relevant information.
• Server builds web page.
• Web page is displayed to client.
• Client's request is satisfied by servlets.
• Lifecycle of Applet:
- Init() : This method is called only when the servlet is loaded into memory for the
first time.
- Service(): The servlets can then read the data provided by the HTTP request with
the help of service() method.
- Destroy(): This method unload the program from the memory.
a) javax.servlet Package
- This is used to implement the servlet.
- Servlet is the most important interface in this package and every servlet
must implement this interface.
- The interfaces are as follows:-
1) Servlet Interface:
- This interface defines all the lifecycle method of servlet. i.e. init(),
service(), destroy().
2) ServletConfig Interface
- This is used to get various initialization parameters.
AJP – 22517
CHAPTER 6 ~ SERVLET
3) ServletContext Interface
- This is used to get info about the servlet environment.
4) ServletRequest Interface
- This interface is used to get information about the client.
AJP – 22517
CHAPTER 6 ~ SERVLET
5) ServletResponse Interface
- It formulates the response for the clients request.
6) Classes:
- Javax.servlet package contains the following classes
AJP – 22517
CHAPTER 6 ~ SERVLET
7) GenericServletClass
- This is used for implementing the lifecycle of the servlet. It implements
servlet and ServletConfig interfaces.
- It is called "Generic" because it does not assume that the protocol it will
process will be HTTP.
b) Javax.servlet.http package
- This servlet works with HTTP request and response.
- The interfaces and methods are as follows.
1) HTTPServletRequest Interface
- It is use to obtain info from clients http request.
AJP – 22517
CHAPTER 6 ~ SERVLET
2) HttpServletResponse Interface
- It is used to formulate an HTTP response to the client.
3) HttpSession Interface
- The servlet can read and write the information using HTTPsession
interface.
4) Class Cookie.
- A cookie is a small piece of information that is stored in the client’s
machine.
- Sometimes cookies are useful to keep track of the user using the client
machine.
AJP – 22517
CHAPTER 6 ~ SERVLET
5) HttpServlet Class
- It extends GenericServlet and is used when developing servlets that receive
and process HTTP requests
6) HttpSessionEvent class
7) HttpSessionBindingEvent class
1. Object getValue() : This function returns the value of bounded or unbounded
attribute.
2. String getName() : This function returns the name being bound or unbound.
3. HttpSession getSession() : This function returns the session to which the listener
can be bound or unbound.
AJP – 22517
CHAPTER 6 ~ SERVLET
• Cookies
- Cookies are some little information that can be left on your computer by the
other computer when we access an internet.
- public void setMaxAge(int expiry) – Sets the maximum age of the cookie
in seconds.