Multiple choice technology programming languages

Assume that there is a file called secure.txt, located at /WEB-INF/securefiles, whose contents are "Password=WebCert." What statements are false about the result of compiling and running the following code? 11 public class CodeTestServlet extends HttpServlet { 12 protected void doGet(HttpServletRequest request, 13 HttpServletResponse response) throws IOException { 14 ServletContext sc = getServletContext(); 15 InputStream is = sc.getResourceAsStream("/WEB-" + 16 "INF/securefiles/secure.txt"); 17 BufferedReader br = new BufferedReader(new InputStreamReader(is)); 18 System.out.println(br.readLine()); 19 } 20 }

  1. The code will not compile.

  2. A RuntimeException will occur at lines 15/16

  3. An IOException will occur at line 18

  4. The string "Password=WebCert" will be returned to the requester

  5. A, B, and C above

  6. A, B, C, and D above.

Reveal answer Fill a bubble to check yourself
F Correct answer
Explanation

The code uses ServletContext.getResourceAsStream() which DOES work for WEB-INF resources from server-side code. The file path '/WEB-INF/securefiles/secure.txt' is correct. getResourceAsStream() returns null if resource not found (no exception). br.readLine() returns the string content (no exception). System.out.println prints to console, not HTTP response. Therefore: A (compile error) is FALSE, B (RuntimeException) is FALSE, C (IOException) is FALSE, D (string returned to requester) is FALSE. The code compiles and runs without exceptions, but does NOT return the string to the HTTP requester. Since A, B, C, and D are all false, answer F (A, B, C, and D above) is correct.