Quiz
O modelo do Servlet
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (10)
1Which method in the HttpServlet class services the HTTP POST request?(Select one)
- AdoPost(ServletRequest, ServletResponse)
- BdoPOST(ServletRequest, ServletResponse)
- CservicePost(HttpServletRequest, HttpServletResponse)
- DdoPost(HttpServletRequest, HttpServletResponse)
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)- AdoGet
- BdoPost
- CdoForm
- DdoHref
- EserviceGet
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)- Aif ( ! res.isSent() )
- Bif ( ! res.isCommitted() )
- Cif ( ! res.isDone() )
- Dif ( ! res.isFlushed() )
- Eif ( ! res.flush() )
4Which of the following lines would initialize the out variable for sending a Microsoft Word file to the browser? (Select one)
- APrintWriter out = response.getServletOutput();
- BPrintWriter out = response.getPrintWriter();
- COutputStream out = response.getWriter();
- DPrintWriter out = response.getOutputStream();
- EOutputStream out = response.getOutputStream();
- FServletOutputStream out = response.getServletOutputStream();
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)
- Aresponse.setContentType("image/gif"); Before
- Bresponse.setContentType("image/gif"); After
- Cresponse.setDataType("image/gif"); Before
- Dresponse.setDataType("image/gif"); After
- Eresponse.setStreamType("image/gif"); Before
- Fresponse.setStreamType("image/gif"); After
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.- AgetParameter("name");
- BgetParameterValue("name");
- CgetParameterValues("name");
- DgetParameters("name");
- EgetValue("name");
- FgetName();
7Which of the following methods would you use to retrieve header values from a request? (Select two)
- AgetHeader() of ServletRequest
- BgetHeaderValue() of ServletRequest
- CgetHeader() of HttpServletRequest
- DgetHeaders() of ServletRequest
- EgetHeaders() of HttpServletRequest
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)- Areq.sendRedirect("collectinfo.html");
- Breq.redirect("collectinfo.html");
- Cres.direct("collectinfo.html");
- Dres.sendRedirect("collectinfo.html");
- Ethis.sendRedirect("collectinfo.html");
- Fthis.send("collectinfo.html");
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)- Asession.setAttribute("userid", userid);
- Breq.setAttribute("userid", userid);
- Cctx.addAttribute("userid", userid);
- Dsession.addAttribute("userid", userid);
- Ethis.addParameter("userid", userid);
- Fthis.setAttribute("userid", userid);
10Which of the following lines would you use to include the output of Data-Servlet into any other servlet? (Select one)
- ARequestDispatcher rd =
request.getRequestDispatcher("/servlet/DataServlet");
rd.include(request, response); - BRequestDispatcher rd =
request.getRequestDispatcher("/servlet/DataServlet");
rd.include(response); - CRequestDispatcher rd = request.getRequestDispatcher();
rd.include("/servlet/DataServlet", request, response); - DRequestDispatcher rd = request.getRequestDispatcher();
rd.include("/servlet/DataServlet", response); - ERequestDispatcher rd = request.getRequestDispatcher();
rd.include("/servlet/DataServlet");
- ARequestDispatcher rd =
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.
- Author
- Luis Felipe Guariento
- Language
- Português
- Views
- 0
- Tags
- Rating
- No ratings yet Rate this quiz