Multiple choice technology programming languages

Write the following code for a JSP page: <%@ page language = "java" %> RESULT PAGE <% PrintWriter print = request.getWriter(); print.println("Welcome"); %> Suppose you access this JSP file, Find out your answer.

  1. A blank page will be displayed.

  2. A page with the text Welcome is displayed

  3. An exception will be thrown because the implicit out object is not used

  4. An exception will be thrown because PrintWriter can be used in servlets only

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

The JSP page will display 'Welcome' because the code uses request.getWriter() which is valid in JSP. While JSP provides an implicit 'out' object, using PrintWriter directly is also allowed. The code correctly obtains a PrintWriter from the request object and writes 'Welcome' to it. There's no rule preventing PrintWriter usage in JSP - it's a valid Java object.