When you enter the url through the browser address bar and request resources through ?, the parameter after ? is called the "query string", which will trigger the doGet() of the background Servlet, because the direct access method through the browser address bar is the GET method .
Let’s take a look at the impact of form’s method attribute on parameter passing.
Original form:
Parameter information: Query string
When specifying the method attribute of the form:
Parameter information: Form data
The response of the above two methods is to display the current page after refreshing. Because the form does not specify the action attribute, the default submitted address is the current page.
Now access the Servlet by specifying the action attribute to learn more about the method attribute.
TestServlet.java core source code:
@WebServlet("/servlet/TestServlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws Servlet Exception , IOException {
response.getWriter().print("doGet()");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().print("doPost( )");
}
}
The third case: method="get" action="/test/servlet/TestServlet"
The fourth case: method="post" action="/test/servlet/TestServlet"