111-120 Flashcards
What is a servlet?
Java servlet is server side technologies to extend the capability of web servers by providing support for dynamic response and data persistence.
What are the differences between post and get methods?
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
What is a request dispatcher?
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
Differences between forward() method and sendRedirect() method?
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
What is the lifecycle of a servlet?
5 stages:
Servlet is loaded
Servlet is instantiated
Servlet is initialized
Service is requested
Servlet is destroyed
How does cookies work in servlets?
Cookies are text data sent by server to the client and it gets saved at the client local machine
What are the differences between ServletConfig and ServletContext?
Servlet config object represent a single servlets
Servlet context represents the whole web application running on a particular JVM and common for all servlets
What are the different methods of session management in servlets?
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