Day 5th: Javaweb's Request/respone
Test Centers: Request and the Response life cycle. and common APIs for two objects ( forwarding and redirection )
1. With regard to request and response the following statements are incorrect (B)(difficulty C)
A, javaweb development is based on the HTTP protocol, Javaweb used to represent the request object, response represents the response object
B, the Request object represents the requests, and the response object represents the response, both of which are created by the browser and sent to the server.
C, the HTTP protocol only specifies how the browser and the server communicate between, and the request and response objects are defined by the Java EE specification, by the Javaweb container is responsible for the creation.
D, the HTTP protocol is the cornerstone of javaweb development, such as the method of request redirection provided in response and the forwarding and inclusion methods provided in the request are based on the HTTP protocol
Answer: BD
Test Center: This did not read the test center, are not garbled. Don't know how to modify
2. Which of the following statements is used by the server to send data can be garbled? (AB) (difficulty B)
A, Response.getoutputstream (). Write ("China". GetBytes ("Utf-8"));
B, Response.getwriter (). Write ("China");
C, response.setcharacterencoding ("Utf-8");
Response.setheader ("Content-type", "text/html;charset=utf-8");
Response.getwriter (). Write ("China");
D, Response.setcontenttype ("Text/html;charset=utf-8");
Response.getwriter (). Write ("China");
Answer: AB
3. With regard to the response object, the following statement is wrong: (a)(difficulty a)
The A.response object is the object that represents the response, which corresponds to the response message in the HTTP protocol, so its API method is defined by the HTTP protocol.
The B.response object is an object inside the server, and the browser only recognizes HTTP response messages and does not know that the response object exists
C.web container gets information from response and organizes it into an HTTP response message sent to the browser
D. The ability to write <metahttp-equiv= "" content= "> to simulate HTTP response headers in HTML
Answer: A
Test Centers: Yes Response and the http detailed understanding of the agreement
Test Centers: Response the closing time of the stream, and Response the data cache area
The following statements are correct: (BD)(difficulty B) [F1]
A, response is the object that represents the response, when the need to output data to the browser as long as the call response body Getoutputstream method or Getwriter method to obtain a stream connected to the browser, you can directly write the data to the browser.
B, the use of response output data, not directly to the browser, but write to the response buffer, wait until the entire service method is returned, the server takes out the information in the response to form a response message returned to the browser.
C, after using the stream to develop the habit of closing the stream, so after the use of response obtained outputstream or writer should be closed as soon as possible to waste resources.
D, after the service method returns, the server will check itself response get OutputStream or writer is closed, if not closed, the server automatically help you shut down, generally do not shut down the two streams themselves.
Answer: BD
Test Centers: Response Two streams cannot be used simultaneously in forwarding
5. What happens if you use a browser to access Servlet1? (D)(difficulty C)
Servlet1:
Response.getoutputstream (). Write ("Preach wisdom". GetBytes ("GBK"));
Request.getrequestdispatcher ("/servlet2"). Forward (Request,response);
Servlet2:
Response.getwriter (). Write ("podcast");
A, browser output Preach Wisdom Podcast
B, browser output garbled
C, the browser output podcast, because in the process of forward will first empty the response buffer, so two words of wisdom lost
D, server-side error
Answer: D
Test Centers: Response Two streams cannot be used simultaneously in forwarding, and Response Chinese garbled problem
6. What happens if you use a browser to access Servlet1? (D) (difficulty B)
Servlet1:
Response.setheader ("Content-type", "text/html;charset=utf-8");
Response.getoutputstream (). Write ("Preach wisdom". GetBytes ("Utf-8"));
Request.getrequestdispatcher ("/servlet2"). Forward (Request,response);
Servlet2:
Response.getoutputstream (). Write ("podcast". GetBytes ("Utf-8"));
A, the browser output "Preach wisdom podcasts" are normal no garbled.
B, the browser output "preach wisdom" for garbled, output "podcast" normal.
C, the browser output "wisdom" normal, Output "podcast" garbled.
D, browser output "podcast" Normal
Answer: D
Test Centers: http protocol, forwarding, and redirection synthesis
7. If you want the user to be able to display the index.jsp page in the Web App directory after Servlet1, and the browser address bar changes to index.jsp, the following code can be implemented in Servlet1 (the Web app is named app)? (AC)(difficulty B)
A, Response.setheader ("Refresh", "0;url=/app/index.jsp");
B, Response.setstatus (302);
Response.setheader ("Location", "/index.jsp");
C, Response.sendredirect (Request.getcontextpath () + "/index.jsp");
D, Request.getrequestdispatcher ("/index.jsp"). Forward (Request,response);
Answer: AC
Test Centers: ServletRequest with the HttpServletRequest the relationship, and Request the creation time and creator
8. Which of the following statements is correct (B) (difficulty C)
A, the ServletRequest class is a request on behalf of the client, so you can use the method it provides to obtain information about the browser: such as getremoteaddr get the IP address of the browser, GetMethod get the request of the browser send request way
B, the HttpServletRequest class provides the GetHeader, Getintheader, Getdateheader methods can obtain the request header information, the difference is that GetHeader returns a string type, The latter two are convenient methods that can be used to quickly get the value of a request header of type int and date type
C, the Request object is created by the Web container, and a browser corresponds to a Request object
D, the Request object is sent by the browser to the server, so one requests for the requested object
Answer: B
Test Centers: Request scope, and Attribute and the Parameter the distinction
9. The statement about the request domain is incorrect: (D)(difficulty A)
A, the request domain is scoped to the entire chain of requests
B, the request domain's life cycle is: The life cycle begins after the server has created a request object for a single demand, and at the end of the response the request object is destroyed at the end of the life cycle.
C, request is scoped to the entire chain of requests, so it is often used by one servlet (or JSP) to pass data through attributes to another servlet (or JSP) on request forwarding.
D. Request parameters can be obtained from the requesting domain.
Answer: D
Test Center: Request parameters, transfer of request parameters in redirected
10. About request parameters The following statement is wrong: (BC)(difficulty C)
A, the request parameter is the browser to access the server at the same time some of the parameter information passed, is the browser and server for message delivery a way.
B, the Request object has the method of adding, acquiring, modifying, deleting requests parameters, so that we can easily in the program to increase the deletion of the browser sent over the request parameters.
C. Request parameters saved in the Request object can be manipulated throughout the chain of requests, so the request object is a domain object, and all the requested parameters make up the original attribute in the request domain.
D, after the request redirection, the request parameters before the request redirection will no longer be accessible.
Answer: BC
Test Centers: Post with the Get Request method, the request parameter is garbled in Chinese
11. About the possible garbled characters in the request parameters, the following description is correct: (ABCD)(difficulty B)
A, what encoding set is used by the browser when using the form to submit request parameters, which is determined by the encoding used when the browser opens the current form page. We can use the Content-type response header to tell the browser what encoding to open the current form page, then the request parameter for this form submission uses that encoding set.
B, the Tomcat server uses ISO8859-1 encoding to decode the request parameters by default, if the browser sends request parameters, the encoding set used is different, there will be garbled.
C, the Request.setcharactereconding method only works on the content of the request body, and the Get method submits the parameter is appended to the URL, so this method can only solve the post garbled
D, for the get way to submit the request parameters, we need to manually after the code to encode and then decode the process to solve garbled characters.
Answer: ABCD
Test Center: Chinese garbled and forwarding execution process combined
12. There are three servlets in the application, with the following code:
Servlet1:
Response.setcharacterencoding ("Utf-8");
Response.setheader ("Content-type", "text/html;charset=utf-8");
Response.getwriter (). Write ("Propagate");
Request.getrequestdispatcher ("/servlet/servlet2"). Forward (Request,response);
Servlet2:
Response.getwriter (). Write ("wisdom");
Request.getrequestdispatcher ("/servlet/servlet3"). Forward (Request,response);
Response.setheader ("Content-type", "text/html;charset=iso8859-1");
Servlet3:
Response.getwriter (). Write ("Sweat");
What kind of output will I get when the browser accesses 1 o'clock: (c)(difficulty C)
A, the browser address bar is still maintained as SERVLET1, output for "spread wisdom sweat"
B, the browser address bar remains Servlet1, the output is a question mark composed of garbled
C, the browser address bar remains Servlet1, output as "sweat"
D, server error, can not be forwarded multiple requests
Answer: C
Test Centers: forwarding and redirection simultaneous use of conflict issues
13. There are three servlets in the Web app named app, with the following code (web App named app):
(D)(difficulty C)
Servlet1:
Response.setcontenttype ("TEXT/HTML;CHARSET=GBK");
Response.getwriter (). Write ("Communication Wisdom");
Request.getrequestdispatcher ("/servlet/servlet2"). Forward (Request,response);
Response.sendredirect ("/app/servlet/servlet3");
Servlet2:
Response.getwriter (). Write ("Harvest Growth");
Servlet3:
Response.setcontenttype ("TEXT/HTML;CHARSET=GBK");
Response.getwriter (). Write ("Sweat");
What kind of output will be available when the browser accesses Servlet1:
A, the browser address bar is still maintained as SERVLET1, the output for "spread wisdom harvest Growth"
B, the browser address bar remains Servlet1, output as "harvest growth"
C, the browser address bar remains Servlet1, output as "sweat"
D, server-side error
Answer: D
Test Center: Forwarding and inclusion
The following statements are correct: (ABC)(difficulty B)[F2]
A, request forwarding and request containment are server-side technologies that do not have any relationship with the browser, and the browser does not know whether the received response message is forwarded or contained.
B, the request forwards the process of forwarding before the response of the response body content data will be lost, the final output will be the request forwarding process of the last node resource data output. While the request contains data that can be implemented to merge multiple resources after the output
C, the use of good request inclusion, can be multiple output content in the same part of the extraction, easy to develop
D. The request contains only dynamic Web resources and cannot contain HTML files
Answer: ABC
Test Centers: servlet Jump between
15. There are Servlet1 and Serlvet2 two servlets in the app name app Web app, and what code below is written in Servlet1 allows the browser to automatically access Servlet2 after the end of the visit Servlet1 (web App named app)
(ACD) (Difficulty B )
A, Response.sendredirect ("/app/servlet2");
B, Response.sendredirect ("Servlet2");
C, Response.setstatues (302);
Response.setheader ("Location", "/app/servlet2");
D, Response.setheader ("Refresh", "0;url=/app/servlet2");
Answer: ABCD
Test Centers: servlet resource files in
16. There is a 1.jpg file under the directory in the app's web app named app, now you need to get the byte input stream in the servlet that points to the file. Which of the following options can be implemented (C)(difficulty B)
A, FileInputStream fin = new FileInputStream ("1.jpg");
B, FileInputStream fin = new FileInputStream ("/1.jpg");
C, Fileinputstreamfin
= New FileInputStream (This.getservletcontext (). Getrealpath ("/1.jpg"));
D, FileInputStream fin =this.getclass (). getClassLoader (). getResourceAsStream ("1.jpg");
Answer: C
Test Centers: servlet Basic API the Use
17.HttpServlet subclass to get the request parameters from the HTTP request, which method should be called? (C)(difficulty A)
A, call the GetAttribute () method of the HttpServletRequest object
B. Call the GetAttribute () method of the ServletContext object
C. Call the GetParameter () method of the HttpServletRequest object
D. Call the GetHeader () method of the HttpServletRequest object
Answer: C
Test Centers: servlet Basic API the Use
What interface is the 18.sendRedirect (java.lang.String URL) method defined in? (C)(difficulty A)
A, HttpSession
B, HttpServletRequest
C, HttpServletResponse
D, Servletresponse
Answer: C
Test Centers: servlet resource files in
19. There is a 1.jpg file in the Web-inf directory in the app name app Web App, now you need to get the byte input stream in the servlet that points to the file. Which of the following options can be implemented: (BD)(difficulty B)
A, FileInputStream fin = new FileInputStream ("/web-inf/1.jpg");
B, Fileinputstreamfin
=new FileInputStream (This.getservletcontext () Getrealpath ("/web-inf/1.jpg"));
C, FileInputStream fin =this.getclass (). getResourceAsStream ("1.jpg");
D, FileInputStream fin =this.getclass (). getResourceAsStream (".. /1.jpg ");
Answer: BD
Test Centers: Requests and redirects
20. The right thing to say about request forwarding and redirection is: (ABCD)(difficulty B)
A. Request forwarding and redirection can be implemented to move to another resource when accessing one resource
B. Request forwarding is a one-time response and redirects to two requests two responses
C. In general, request forwarding should be used to reduce browser access to the server and reduce server pressure
D. If you need to change the browser's address bar, or change the function of the browser's refresh button, you need to use redirection
Answer: ABCD
[F1] Ambiguous
[F2] Objection B option
Dark Horse day05 response&request small test has difficulty oh!