GoConqr has a new look! Let us know what you think.

Quiz

O modelo do Servlet

Luis Felipe Guariento 10 questions

Take the quiz

Questions in this quiz (10)

  1. 1Which method in the HttpServlet class services the HTTP POST request?(Select one)
    1. AdoPost(ServletRequest, ServletResponse)
    2. BdoPOST(ServletRequest, ServletResponse)
    3. CservicePost(HttpServletRequest, HttpServletResponse)
    4. DdoPost(HttpServletRequest, HttpServletResponse)
  2. 2Consider the following HTMLpage code:
    <html><body>
    <a href="/servlet/HelloServlet">POST</a>
    </body></html>

    Which method of HelloServlet will be invoked when the hyperlink displayed by the above page is clicked? (Select one)
    1. AdoGet
    2. BdoPost
    3. CdoForm
    4. DdoHref
    5. EserviceGet
  3. 33. Consider the following code for the doGet() method:

    public void doGet(HttpServletRequest req, HttpServletResponse res) {
    PrintWriter out = res.getWriter();
    out.println("<html><body>Hello</body></html>");
    //1
    if(req.getParameter("name") == null){
    res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
    }

    Which of the following lines can be inserted at //1 so that the above code does not throw any exception? (Select one)
    1. Aif ( ! res.isSent() )
    2. Bif ( ! res.isCommitted() )
    3. Cif ( ! res.isDone() )
    4. Dif ( ! res.isFlushed() )
    5. Eif ( ! res.flush() )
  4. 4Which of the following lines would initialize the out variable for sending a Microsoft Word file to the browser? (Select one)
    1. APrintWriter out = response.getServletOutput();
    2. BPrintWriter out = response.getPrintWriter();
    3. COutputStream out = response.getWriter();
    4. DPrintWriter out = response.getOutputStream();
    5. EOutputStream out = response.getOutputStream();
    6. FServletOutputStream out = response.getServletOutputStream();
  5. 5You need to send a GIF file to the browser. Which of the following lines should be called after (or before) a call to response.getOutputStream()? (Select one)
    1. Aresponse.setContentType("image/gif"); Before
    2. Bresponse.setContentType("image/gif"); After
    3. Cresponse.setDataType("image/gif"); Before
    4. Dresponse.setDataType("image/gif"); After
    5. Eresponse.setStreamType("image/gif"); Before
    6. Fresponse.setStreamType("image/gif"); After
  6. 6Consider the following HTML page code:
    <html><body>
    <form name="data" action="/servlet/DataServlet" method="POST">
    <input type="text" name="name">
    <input type="submit" name="submit">
    </form>
    </body></html>

    Identify the two methods that can be used to retrieve the value of the name parameter when the form is submitted.
    1. AgetParameter("name");
    2. BgetParameterValue("name");
    3. CgetParameterValues("name");
    4. DgetParameters("name");
    5. EgetValue("name");
    6. FgetName();
  7. 7Which of the following methods would you use to retrieve header values from a request? (Select two)
    1. AgetHeader() of ServletRequest
    2. BgetHeaderValue() of ServletRequest
    3. CgetHeader() of HttpServletRequest
    4. DgetHeaders() of ServletRequest
    5. EgetHeaders() of HttpServletRequest
  8. 8Consider the following code:
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException{
    if(req.getParameter("switch") == null){
    //1
    }
    else{
    //other code
    }
    }

    Which of the following lines can be inserted at //1 so that the request is redirected to collectinfo.html page? (Select one)
    1. Areq.sendRedirect("collectinfo.html");
    2. Breq.redirect("collectinfo.html");
    3. Cres.direct("collectinfo.html");
    4. Dres.sendRedirect("collectinfo.html");
    5. Ethis.sendRedirect("collectinfo.html");
    6. Fthis.send("collectinfo.html");
  9. 99. Consider the following code:

    public void doGet(HttpServletRequest req, HttpServletResponse res){
    HttpSession session = req.getSession();
    ServletContext ctx = this.getServletContext();
    if(req.getParameter("userid") != null){
    String userid = req.getParameter("userid");
    //1
    }
    }

    You want the userid parameter to be available only to the requests that come from the same user. Which of the following lines would you insert at //1? (Select one)
    1. Asession.setAttribute("userid", userid);
    2. Breq.setAttribute("userid", userid);
    3. Cctx.addAttribute("userid", userid);
    4. Dsession.addAttribute("userid", userid);
    5. Ethis.addParameter("userid", userid);
    6. Fthis.setAttribute("userid", userid);
  10. 10Which of the following lines would you use to include the output of Data-Servlet into any other servlet? (Select one)
    1. ARequestDispatcher rd =
      request.getRequestDispatcher("/servlet/DataServlet");
      rd.include(request, response);
    2. BRequestDispatcher rd =
      request.getRequestDispatcher("/servlet/DataServlet");
      rd.include(response);
    3. CRequestDispatcher rd = request.getRequestDispatcher();
      rd.include("/servlet/DataServlet", request, response);
    4. DRequestDispatcher rd = request.getRequestDispatcher();
      rd.include("/servlet/DataServlet", response);
    5. ERequestDispatcher rd = request.getRequestDispatcher();
      rd.include("/servlet/DataServlet");

Information

Description
Concursos Públicos Desenvolvimento de Software (OCEJWCD 6 ONLINE COURSE) Quiz on O modelo do Servlet, created by Luis Felipe Guariento on 15/05/2018.
Language
Português
Views
0
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?