nerdexam
Oracle

1Z0-900 · Question #24

Which two approaches would result in the current date being added to the output of a JSP? (Choose two.)

Options B and C are correct (note: printIn in B/A likely renders as println - a common font artifact in exam materials where lowercase l resembles uppercase I). C (<%= new java.util.Date() %>) is correct because the JSP expression tag (<%= %>) evaluates any Java expression and…

Create Java Web Applications using JSPs

Question

Which two approaches would result in the current date being added to the output of a JSP? (Choose two.)

Options

  • A<%= out.printIn(new java.util.Date()) %>
  • B<% out.printIn(new java.util.Date()); %>
  • C<%= new java.util.Date() %>
  • D<% System.out.printIn(new java.util.Date()); %>

Explanation

Options B and C are correct (note: printIn in B/A likely renders as println - a common font artifact in exam materials where lowercase l resembles uppercase I).

C (<%= new java.util.Date() %>) is correct because the JSP expression tag (<%= %>) evaluates any Java expression and writes its toString() result directly to the HTTP response - no semicolon, no method call needed.

B (<% out.println(new java.util.Date()); %>) is correct because the scriptlet tag (<% %>) executes Java statements, and out is a JSP implicit object (JspWriter) with a println() method that writes to the response; note the required semicolon.

A is wrong because mixing <%= %> with out.println() is redundant and broken - the expression tag would try to output the return value of println(), which is void, producing nothing useful.

D is wrong because System.out.println() writes to the server console (standard output), not the HTTP response the client sees.

Memory tip: Think of <%= %> as "equals equals output" - whatever expression follows gets printed as-is. Think of <% %> as "raw Java code" - you're responsible for writing to out yourself, just like you would in a servlet.

Topics

#JSP expression tags#JSP scriptlet tags#implicit out object#output generation

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice