If you want to make money online : Register now

The HttpServletRequest interface captures the functionality for a request object that is passed to a HTTP servlet. It provides access to an input stream and allows the servlet to read data from the client. The HttpServletRequest interface extends the ServletRequest interface.

public interface HttpServletRequest extends ServletRequest

The servlet container creates an HttpServletRequest object and passes it as an
argument to the servlet's service methods (doGet, doPost etc). The HttpServletRequest
interface has many methods. Some of the commonly used methods of HttpServletRequest are:

  1. getParameter()
    It returns the value associated with a parameter sent to the servlet as a part of a
    GET or POST request. The name argument represents the parameter name.
    public String getParameter(String name)
  1. getQueryString()
    It returns the query string that is contained in the request URL if any. This
    method returns null if the URL does not have a query string. A query string is
    defined as any information following a ? character in the URL.

public String getQueryString()

  1. getCookies()
    The getCookies() method returns an array of Cookie objects found in the client request. This method does not take any parameters and throws no exceptions. Cookies are used to uniquely identify clients to servlet. In case of no cookies in the request, an empty array is returned.

public Cookie[] getCookies()

  1. getHeader()
    It returns the value of the specified request header as a String. In case if the request did not include a header of the specified name, this method will return null. If there are multiple headers with the same name, this method returns the
    first header in the request. The header name is case insensitive.
    public String getHeader(String name)

5. getMethod
It returns the name of the HTTP method used to make the request. Typical return
values are ‘GET’, ‘POST’, or ‘PUT’
public String getMethod()

  1. getSession()
    It returns the current session associated with the request or if the request does not
    have a session, creates one.

public HttpSession getSession(boolean create)
public HttpSession getSession()

The javax.servlet.http package contains a number of classes and interfaces that are used to create HTTP protocol-specific Servlets. The abstract class HttpServlet is a base class for user defined HTTP Servlets which provide methods. The basic methods such as doGet and doPost are for handling HTTP-specific services. When you are developing your own servlets then you can use HttpServlet class which is extended from GenericServlet.

public abstract class HttpServlet

Unlike with GenericServlet, when you extend HttpServlet, you can skip implement
ing the service() method. The HttpServlet class has already implemented the service()
method. The following are the prototype of the service() method:

protected void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException

When the HttpServlet.service() method is invoked, it first reads the method type
stored in the request, and on that basis it determines the method to be invoked. For
example if the method type is GET, it will call doGet() method, and if the method
type is POST, it will call doPost() method. These methods have the same parameter as
the service() method.

There are many interfaces in javax.servlet.http package but the three important
interfaces HttpServletRequest, HttpServletResponse and HttpSession are described
below:

 The Java Serializable interface (java.io.Serializable) is a marker interface. It means that it contains no methods. Therefore, a class implementing Serializable does not have to implement any specific methods.

 An object of ServletConfig is created by the servlet container for each servlet. This object is used to pass configuration related information to a servlet during start up. The getServletConfig() method is used to return the object of ServletConfig. It contains name/value pairs of initialization parameters for the servlet. It defines four methods such as getServletContext(), getServletName(), getInitParameter() and getInitParameterNames() for accessing this information.

All servlets must implement the Servlet interface either directly or indirectly. Java servlets class does not have a main() method, so all servlets must implement the javax.servlet.Servlet interface. It defines five methods, including three life-cycle methods. You may read the life-cycle methods such as init(), service() and destroy() in the subsequent section 2.5 and other two methods are getServletConfig() and getServletInfo().

 Structure of a state space:

The structures of state space are trees and graphs. A tree has one and only one path from any
point to any other point. Graph consists of a set of nodes (vertices) and a set of edges (arcs). Arcs
establish relationship (connections) between the nodes, i.e., a graph has several paths to a given
node. Operators are directed arcs between nodes.

The method of solving problem through AI involves the process of defining the search space,
deciding start and goal states and then finding the path from start state to goal state through
search space.

Search process explores the state space. In the worst case, the search explores all possible paths
between the initial state and the goal state.

Problem Solution:

In a state space, a solution is a path from the initial state to a goal state or sometime just a goal
state. A numeric cost is assigned to each path. It also gives the cost of applying the operators to
the states. A path cost function is used to measure the quality of solution and out of all possible
solutions, an optimal solution has the lowest path cost. The importance of cost depends on the
problem and the type of solution asked.

Problem formulation:

Many problems can be represented as state space. The state space of a problem includes: an
initial state, one or more goal state, set of state transition operator (or a set of production rules),
used to change the current state to another state. This is also known as actions. A control
strategy is used that specifies the order in which the rules will be applied. For example, Depthfirst search (DFS), Breath-first search (BFS) etc. It helps to find the goal state or a path to the
goal state.

In general, a state space is represented by 4 tuples as follows:𝑺𝒔
: [𝑺, 𝒔𝟎, 𝑶,𝑮]

Where S: Set of all possible states.
𝒔𝟎: start state (initial configuration) of the problem, 𝑠଴ ∈ 𝑆 .
O: Set of production rules (or set of state transition operator)
used to change the state from one state to another. It is the set
of arcs (or links) between nodes.

The production rule is represented in the form of a pair. Each pair consists of a left side that
determines the applicability of the rule and a right side that describes the action to be performed,
if the rule is applied.

G: Set of Goal state, 𝐺 ∈ 𝑆.

 Step 1: (α_1-> (α_2 ∨α_3)) (Premise)

Step 2: α_1(Assumed Premise)

Step 3: α_2 ∨α_3 (Modus Ponens, Step 1, 2)

Step 4: α_2 -> ~α_1 (Premise)

Step 5: ~α_2 (Modus Tollens, Step 2, step 4)

Step 6: α_3 (Disjunctive Syllogism, Step 1, 2, 4)

Step 7: α_4-> ~α_3 (Premise)

Step 8: ~α_4 (Modus Tollens, Step 1, 2, 4, 7)

Step 9: α_1 -> ~α_4 (Step 2, 4)

Hence proved