About HttpServletRequest
The HttpServlet’s doGet() and doPost() methods take an
ServletRequest interface
(javax.servlet.ServletRequest)
HttpServletRequest and an HttpServletResponse.
The service() method determines whether doGet() or
doPost() runs based on the HTTP Method (GET, POST,
etc.) of the HTTP request.
POST requests have a body; GET requests do not,
although GET requests can have request parameters
appended to the request URL (sometimes called “the
query string”).
GET requests are inherently (according to the HTTP
spec) idempotent. They should be able to run multiple
times without causing any side effects on the server. GET
requests shouldn’t change anything on the server. But
you could write a bad, non-idempotent doGet() method.
<<interface>>
ServletRequest
getAttribute(String)
getContentLength()
getInputStream()
getLocalPort()
getRemotePort()
getServerPort()
getParameter(String)
getParameterValues(String)
getParameterNames()
// MANY more methods...
POST is inherently not idempotent, so it’s up to you to
design and code your app in such a way that if the client
sends a request twice by mistake, you can handle it.
If an HTML form does not explicitly say “method=POST”,
the request is sent as a GET, not a POST. If you do not
have a doGet() in your servlet, the request will fail.
You can get parameters from the request with the
getParameter(“paramname”) method. The return value is
always a String.
If you have multiple parameter values for a given param-
eter name, use the getParameterValues(“paramname”)
method that returns a String array.
You can get other things from the request object including
headers, cookies, a session, the query string, and an
input stream.
ServletRequest interface
(javax.servlet.ServletRequest)
HttpServletRequest and an HttpServletResponse.
The service() method determines whether doGet() or
doPost() runs based on the HTTP Method (GET, POST,
etc.) of the HTTP request.
POST requests have a body; GET requests do not,
although GET requests can have request parameters
appended to the request URL (sometimes called “the
query string”).
GET requests are inherently (according to the HTTP
spec) idempotent. They should be able to run multiple
times without causing any side effects on the server. GET
requests shouldn’t change anything on the server. But
you could write a bad, non-idempotent doGet() method.
<<interface>>
ServletRequest
getAttribute(String)
getContentLength()
getInputStream()
getLocalPort()
getRemotePort()
getServerPort()
getParameter(String)
getParameterValues(String)
getParameterNames()
// MANY more methods...
POST is inherently not idempotent, so it’s up to you to
design and code your app in such a way that if the client
sends a request twice by mistake, you can handle it.
If an HTML form does not explicitly say “method=POST”,
the request is sent as a GET, not a POST. If you do not
have a doGet() in your servlet, the request will fail.
You can get parameters from the request with the
getParameter(“paramname”) method. The return value is
always a String.
If you have multiple parameter values for a given param-
eter name, use the getParameterValues(“paramname”)
method that returns a String array.
You can get other things from the request object including
headers, cookies, a session, the query string, and an
input stream.