Week6 Flashcards
What is HTTP?
An application layer protocol in the internet protocol suite model for distributed hypermedia information.
What is HTTP used for?
It is a protocol that is used for fetching resources such as HTML documents. It is the foundation of ANY exchange on the Web.
HTTP is a client-server protocol. T/F?
True.
What is The Method Attribute used for?
This is used to specify the HTTP method used to send data while submitting the form.
Two options in The Method Attribute?
GET and POST.
What is a GET?
Part of The Method Attribute.
After submission of the form, the form values will be visible in the address bar of the browser.
What is a POST?
Part of The Method Attribute.
After submission of the form, the form values will NOT be visible in the address bar of the browser.
What does it mean for an HTTP verb to be idempotent?
It means an identical request can be made once or several times in a row with the same effect while leaving the server in the same state. It should not have any side-effects.
Explain The Value Attribute.
Specifies an initial value for an input field. It also serves as the attribute to use when providing a button label for submit and reset input elements.
Explain the placeholder Attribute.
Specifies a hint that describes the expected value of the input field (a sample value or a short description of the expected format). The short hint is displayed in the input field before the user enters a value.
Explain the required attribute.
It indicates an input field that must be filled out before submitting the form. In most modern browsers, it will prevent the user from submitting the form until an acceptable value is entered.
Explain the min and max attributes.
The min and max attributes specify the minimum and maximum values for an input field.
Explain the Action attribute.
It indicates where the form data will be processed. Typically the value is a URL of a server. Generally, the form data is sent to a webpage on the webserver after the user clicks on the submit button.
Explain the Target Attribute.
This is used to specify whether the submitted result will open in the current window, a new tab or on a new frame. The default value used is “self” which results in the form submission in the same window. To make the result display in a new browser tab, the value should be set to “blank”.
Explain the Name Attribute.
The name attribute should be provided for each input element. It is not required, but the value provides a label for the data once the form is submitted. If the name attribute is not specified in an input field then the data of that field will not be sent.
What is HTML form?
This is a section of a document that contains controls such as text fields, password fields, checkboxes, radio buttons, submit button, menus, etc. Using these elements the page can collect information from a user which is typically submitted to a web server.
Why use an HTML Form?
We use forms to collect some information/data form the user.
What are the contents of an HTTP request?
HTTP version
URL
HTTP verb / method
Request Headers
Request Body
What are the contents of an HTTP response?
HTTP response contents
HTTP version
Status code
Response Headers
Response Body
What is a URL?
Uniform Resource Locator. The address of a given unique resource on the Web.
What is an HTTP request header?
An HTTP header that can be used in an HTTP request to provide information about the request context, so that the server can tailor the response.
What is a servlet?
A Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Commonly used to extend the applications hosted by web servers.
What is a servlet container?
These control servlets. When an application running in a web server receives a request, the Server hands the request to the Servlet Container - which in turn passes it to the target servlet.
Name the 4 parts to the servlet hierarchy in order from top to bottom.
Servlet interface.
Generic servlet.
Http servlet.
MyServlet.
Explain the servlet interface.
The servlet interface of the javax.servlet package defines methods that the Web container calls to manager the servlet life cycle.
Explain public void destroy()
The Web container calls the destroy() method just before removing the servlet instance from service.
What are the three life cycle methods of a Servlet?
init()
service()
destroy()
What are the 5 steps in the servlet life cycle in order?
- Loading of Servlet.
- Creating an instance of Servlet.
- Invoke init() method once.
- Invoke service() method repeatedly for each client request.
- Invoke destroy() method once.
Explain the first step of the Servlet Life Cycle, Loading of Servlet.
When the application server (ex. Apache Tomcat) starts up, the servlet conatiner deploys and loads all the servlet classes.
Explain the 2nd step of the Servlet Life Cycle, Creating an instance of Servlet.
Once all the Servlet classes are loaded, the servlet container creates only one instance for each servlet class.
Explain the 3rd step of the Servlet Life Cycle, Invoke init() method once.
What is the init() method signature?
Once all the servlet classes are instantiated, the init() method is invoked for each instantiated servlet. The init() method is used to initialize the servlet. The init() method is called only once.
public void init() throws ServletException {
}
Explain the 4th step of the Servlet Life Cycle, Invoke service() method repeatedly for each client request.
What is the service method signature?
The servlet container calls the service method each time a request for the servlet is received. The service() method determines the type of Http request (GET, POST, PUT, DELETE, etc.) also calls doGet(), doPost(), doPut(), doDelete(), etc. methods as appropriate.
public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
}
Explain the 5th step of the Servlet Life Cycle, Invoke destroy() method once.
What is the destroy() method signature?
The destroy() method is called only once at the end of the a servlet’s life. The servlet container calls this method before removing the servlet instance from the service.
public void destroy() {
}
What are the 6 steps to creating a servlet using the HttpServlet class approach?
- Create a directory structure
- Create a Servlet
- Compile the Servlet
- Create a deployment descriptor
- Start the server and deploy the project, configure Tomcat.
- Access the Servlet.