111-120 Flashcards

1
Q

What is a servlet?

A

Java servlet is server side technologies to extend the capability of web servers by providing support for dynamic response and data persistence.

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

What are the differences between post and get methods?

A

Get - Limited amount of data can be sent because data is sent in the header
Post - Large amount of data can be sent because data is in the body

Get- Not secured because data is exposed in the URL bar
Post- Secured because data is not exposed in the URL bar

Get- Can be bookmarked
Post- Can’t be bookmarked

Get- Idempotent - Can be called different times with the same outcome
Post- Non-Idempotent

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

What is a request dispatcher?

A

RequestDispatcher interface is used to forward the request to another resource that can be HTML, JSP or another servlet in the same application.
Two methods defined in this interface:
1. void forward() - request-> servlet1 -> servlet2 -> final response
2. void include() - request-> servlet1 -> servlet2 -> response of servlet 2 included in response -> Final response

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

Differences between forward() method and sendRedirect() method?

A

forward() - sends the same request to another resource
sendRedirect() - sends a new request always because it uses the URL of the browser

forward() - works art server side
sendRedirect() - works at client side

forward() - works only within the server
sendRedirect() - works within and outside the server

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

What is the lifecycle of a servlet?

A

5 stages:
Servlet is loaded
Servlet is instantiated
Servlet is initialized
Service is requested
Servlet is destroyed

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

How does cookies work in servlets?

A

Cookies are text data sent by server to the client and it gets saved at the client local machine

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

What are the differences between ServletConfig and ServletContext?

A

Servlet config object represent a single servlets
Servlet context represents the whole web application running on a particular JVM and common for all servlets

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

What are the different methods of session management in servlets?

A

A session is a conversational state between client and server and it can consist of multiple request and response. Since HTTP and Web Server are both stateless, the only way to maintain a session is when some unique information about the session (session id) is passed between every request and response.
Common ways of session management:
User Authentication, HTML hidden field, Cookies, URL rewriting, Session management api

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