How would servlet code from a service method (e.g., doPost()
) retrieve the value of the “User-Agent” header from the request? (Choose all that apply.)
( API)
A. | String userAgent = request.getParameter("User-Agent"); | |
B. | String userAgent = request.getHeader("User-Agent"); | |
C. | String userAgent = request.getRequestHeader("Mozilla"); | |
D. | String userAgent = getServletContext().getInitParameter("User-Agent"); |
Which HTTP methods are used to show the client what the server is receiving? (Choose all that apply.)
(HF 4, HTTP methods)
Which method of HttpServletResponse
is used to redirect an HTTP request to another URL?
(API)
Which HTTP methods are NOT considered idempotent? (Choose all that apply.)
(HF 4, idempotent requests)
Given req
is a HttpServletRequest
, which gets a binary input stream? (Choose all that apply.)
(API)
|
| |
B. | ServletInputStream s = req.getInputStream(); | |
C. | BinaryInputStream s = req.getBinaryStream(); | |
| ServletInputStream s = req.getBinaryStream(); |
How would you set a header named “CONTENT-LENGTH” in the HttpServletResponse
object? (Choose all that apply.)
(API)
|
| |
B. | response.setHeader("CONTENT-LENGTH","1024"); | |
C. | response.setStatus(1024); | |
| response.setHeader("CONTENT-LENGTH",1024); |
Choose the servlet code fragment that gets a binary stream for writing an image or other binary type to the HttpServletResponse
.
(API)
|
| |
B. | ServletOutputStream out = response.getOutputStream(); | |
C. | java.io.PrintWriter out = new PrintWriter(response.getWriter()); | |
| ServletOutputStream out = response.getBinaryStream(); |
Which methods are used by a servlet to handle form data from a client? (Choose all that apply.)
(API)
A. |
| |
B. |
| |
C. |
| |
D. |
| |
E. |
| |
F. |
|
Which of the following methods are declared in HttpServletRequest
as opposed to in ServletRequest
? (Choose all that apply.)
(API)
How should servlet developers handle the HttpServlet
’s service()
method when extending HttpServlet
? (Choose all that apply.)
(API)
A. | They should override the | |
B. | They should call the | |
C. | They should call the | |
D. | They should override at least one |