Servlets Flashcards
What is a servlet?
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
What is a servlet container?
It contains one to many Servlets and is primarily responsible for mapping the servlets to different addresses. They configure our servlets.
What is the deployment descriptor?
A deployment descriptor describes the deployment information of a Servlet. The file it uses is an XML file.
What file configures your servlet container?
The xml file
Is eager or lazy loading of servlets the default?
Lazy loading is the default.
What are some tags you would find in the web.xml file?
<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>
What is the difference between the ServletConfig and ServletContext objects? How do you retrieve these in your servlet?
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.
What is the purpose of the RequestDispatcher?
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.
Explain the difference between RequestDispatcher.forward() and HttpServletResponse.sendRedirect()
A RequestDispatcher forward() is used to forward the same request to another resource whereas ServletResponse sendRedirect() is a two step process.
What is object mapping?
The process of building object wrappers around legacy interfaces. This makes the legacy system available in an OO fashion
What is the difference between getParameter() and getAttribute() methods?
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.
Explain the front controller design pattern
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.