Servlet notes 1

Servlet interface defines five abstract methods:

void intit (ServletConfig config) accepts a parameter of type ServletConfig, initial configuration information is transmitted to the Servlet.
ServletConfig getServletConfig () for acquiring the configuration information of the object Servlet, the Servlet returns ServletConfig object
String getSetvletInfo () Returns a string containing information about the Servlet
void service (ServletRequest request, ServletResponse response ) is responsible for responding to user requests, when the container upon receiving the request clients to access Servlet object, it will call this method. We construct a represents a client request object information and a ServletRequest ServletResponse object response for delivery to the client service () method as a parameter. In service () method, and the requested information can be obtained manner ServletRequest object by the client, after the request is processed, an object method calls ServletReponse setting response information
void destory () is responsible for releasing resources occupied by the object Servlet.

protected void doGet (HttpServletRequest req, HttpServletResponse resp) for processing GET method of the HTTP request type
protected void doPost (HttpServletRequest req, HttpServletResponse resp) for processing HTTP POST method request type
protected void doPut (HttpServletRequest req, HttpServletResponse resp) a method for processing a HTTP PUT request type
common method HttpServlet class:
protected void doHead (the HttpServletRequest REQ, the HttpServletResponse RESP) HEAD method for processing an HTTP request type
protected void doDelete (HttpServletRequest req, HttpServletResponse resp) for processing DELETE the method of HTTP request type
method protected void doOptions (HttpServletRequest req, HttpServletResponse resp) for processing HTTP OPTIONS request type
protected void doTrace (HttpServletRequest req, HttpServletResponse resp) a method for processing an HTTP request type TRACE
Here Insert Picture Description
Here Insert Picture Description

Servlet Creation and Configuration
Here Insert Picture DescriptionHere Insert Picture Description

Here Insert Picture Description

  1. GetParmServlet.java
  2. index.html
在这里插入代码片
```<body>
        <form action="GetParmServlet" method="post">
            <input type="text" name="user"/>
            <br>
            <input type="submit" value="Submit" />
        </form>
    </body>
//GetParmServlet.java
       String userString= request.getParameter("user");         
       out.println("<h1>hello " + userString + "</h1>");
```javascript
在这里插入代码片

Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture Description
Here Insert Picture Description

Published 17 original articles · won praise 0 · Views 284

Guess you like

Origin blog.csdn.net/qq_41757128/article/details/104680302