Servlets Flashcards

1
Q

What is a servlet?

A

Programs that run on a web or application server and act as a middle layer between a request from a web browser or other HTTP client and databases or applications on the HTTP server.

Alternative answer:

A Java object to handle incoming requests
not solely HTTP. Servlets can generate responses and process requests using Java Logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a servlet container?

A

It contains one to many Servlets and is primarily responsible for mapping the servlets to different addresses. They configure our servlets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the deployment descriptor?

A

A deployment descriptor describes the deployment information of a Servlet. The file it uses is an XML file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What file configures your servlet container?

A

The xml file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Is eager or lazy loading of servlets the default?

A

Lazy loading is the default.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some tags you would find in the web.xml file?

A

<context-param> - This element declares servlet context initialization parameters for a Web Application. These are parameters that you define and are available throughout your Web application.

<listener> - This element defines an application listener. A listener class responds to the web application events.

<servlet> - This element defines servlet used in the application. If a jsp-file is specified and the <load-on-startup> element is present, then the JSP is precompiled and loaded when WebLogic Server starts in the order of value given in <load-on-startup>.
</load-on-startup></load-on-startup></servlet></listener></context-param>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between the ServletConfig and ServletContext objects? How do you retrieve these in your servlet?

A

The servletconfig object refers to the single servlet whereas servletcontext object refers to the whole web application ServletConfig is implemented by the servlet container to initialize a single servlet using init(). That is, you can pass initialization parameters to the servlet using the web.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of the RequestDispatcher?

A

The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interface can also be used to include the content of another resource also. It is one of the way of servlet collaboration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain the difference between RequestDispatcher.forward() and HttpServletResponse.sendRedirect()

A

A RequestDispatcher forward() is used to forward the same request to another resource whereas ServletResponse sendRedirect() is a two step process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is object mapping?

A

The process of building object wrappers around legacy interfaces. This makes the legacy system available in an OO fashion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between getParameter() and getAttribute() methods?

A

getParameter() returns http request parameters. Those passed from the client to the server. getAttribute() is for server-side usage only - you fill the request with attributes that you can use within the same request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain the front controller design pattern

A

The front controller design pattern means that all requests that come for a resource in an application will be handled by a single handler and then dispatched to the appropriate handler for that type of request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly