ALL PRJ321 || 100% NO ERROR.
E. Web page returned showing a heading and the current date correct answers 1. What will be
the most likely outcome of attempting to access the following JSP for the second
time? (Choose one.)
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html><head><title>Chapter 6 Question 1</title></head>
<body>
<h1>Chapter 6 Question 1</h1>
<%!
public void jspInit() {
System.out.println("First half of jspInit()");
%>
<%> new Date() %>
<%!
System.out.println("Second half of jspInit()");
}
%>
</body></html>
A. Translation error (HTTP response code of 500)
B. Page not found error (HTTP response code of 404)
C. Web page returned showing a heading and the current date; two lines of output written to
the server log
D. Web page returned showing "First half of jspInit()," "Second half of jspInit()," a heading,
and the current date
E. Web page returned showing a heading and the current date
D. 3 correct answers 2. What is output to the web page on the second access to the same
instance of the following JSP?
(Choose one.)
<%@ page language="java" %>
<html>
<head><title>Chapter 6 Question 2</title></head>
<body>
<h1>Chapter 6 Question 2</h1>
<%! int x = 0; %>
<%!
public void jspInit() {
System.out.println(x++);
}
%>
<%= x++ %>
<% System.out.println(x); %>
<% jspInit(); %>
</body></html>
A. 0
B. 1
C. 2
D. 3
,E. 4
F. Page does not translate.
G. Page translates, but there is another runtime error.
A. Expression embedded in declaration. correct answers 3. For what reason does the
following JSP fail to translate and compile? (Choose one.)
<%@ page language="java" %>
<html>
<head><title>Chapter 6 Question 3</title></head>
<body>
<h1>Chapter 6 Question 3</h1>
<%! int x; %>
<%!
public void jspDestroy() {
System.out.println("self-destructing");
} %>
<%!
public void jspInit() {
System.out.println(<%= x %>);
}
%>
</body></html>
A. Expression embedded in declaration.
B. Data member x not initialized before use.
C. Local variable x not initialized before use.
D. Placement of jspDestroy() method before jspInit() method.
E. The page actually compiles and translates without any problem.
F. None of the above.
A. The _jspService() method is called from the generated servlet's service() method.
D. All servlet methods are accessible from the jspInit() method. correct answers 4. Which of
the following are true statements about the JavaServer Page life cycle?
(Choose two.)
A. The _jspService() method is called from the generated servlet's service() method.
B. jspInit() is only ever called on the fi rst request to a JSP instance.
C. jspDestroy() is only ever called on the last request to a JSP instance.
D. All servlet methods are accessible from the jspInit() method.
E. You cannot override or provide a no-parameter init() method in a JSP page.
A. Cannot resolve symbol compilation error.
E. Duplicate method compilation error. correct answers 5. What is the consequence of
attempting to access the following JSP page?
(Choose two.)
<%@ page language="java" %>
<html>
<head><title>Chapter 6 Question 5</title></head>
<body>
<h1>Chapter 6 Question 5</h1>
<%!public void _jspService(HttpServletRequest request,
HttpServletResponse response) {
,out.write("A");
} %>
<% out.write("B"); %>
</body>
</html>
A. Cannot resolve symbol compilation error.
B. "A" is output to the response.
C. "B" is output to the response.
D."A" is output to the response before "B."
E. Duplicate method compilation error.
F. "B" is output to the response before "A."
B. A translation error occurs. correct answers 6. What is the result of attempting to access the
following JSP page? (Choose one.)
<html>
<head><title>Chapter 6 Question 6</title></head>
<body>
<h1>Chapter 6 Question 6</h1>
<%! public String methodA() {
return methodB();
}
%>
<%! public String methodB() {
return methodC();
}
%>
<% public String methodC() {
return "Question 6 Text";
}
%>
<h2><%= methodA() %></h2>
</body>
</html>
A. "Question 6 Text" is output to the resulting web page.
B. A translation error occurs.
C. A runtime error occurs.
D. The text between the <h1></h1> HTML tags appears, followed by a Java stack
trace.
E. The web page is blank.
B. In JSP technology, it's a bad idea to get hold of the PrintWriter directly from the response.
H. The page has a compilation error for other reasons. correct answers 8. What true
statements can you make about the following JSP page source? The line
numbers are for reference only and should not be considered part of the source.
(Choose two.)
01 <%@ page import="java.io.*" %>
02 <html>
03 <head><title>Chapter 6 Question 8</title></head>
04 <body>
05 <%
, 06 PrintWriter out = response.getWriter();
07 out.write("P");
08 %>
09 <% out.write("Q"); %>
10 </body>
11 </html>
A. In line 09, the scriptlet markers should not be on the same line as the Java source
statement.
B. In JSP technology, it's a bad idea to get hold of the PrintWriter directly from the response.
C. "P" will be written to the response, followed by "Q."
D. "Q" will be written to the response, followed by "P."
E. Only "Q" will be written to the response.
F. The page has a compilation error because of a directive syntax error.
G. The page has a compilation error because the import in the directive syntax is for
the wrong Java package.
H. The page has a compilation error for other reasons.
A. It is legal to embed a <%--style comment inside another comment.
C. It is legal to embed an expression inside a declaration.
D. It is legal to embed an expression inside a directive. correct answers 9. Which of the
following are false statements to make about JSP scripting elements?
(Choose three.)
A. It is legal to embed a <%--style comment inside another comment.
B. It is legal to embed an expression inside a scriptlet.
C. It is legal to embed an expression inside a declaration.
D. It is legal to embed an expression inside a directive.
E. It is legal to include a declaration at any point in the JSP page source, provided that
it appears outside of other elements.
F. It is legal to embed a scriptlet inside an expression inside a <%--style comment.
D. The JSP page would compile if one of the percent (%) signs were removed. correct
answers 10. What is the result of attempting to access the following JSP page source?
(Choose one.)
<% <%-- for (int i = 0; i < 10; i++) {
<%-- if(i==3) System.out.println("i is 3!");--%>
System.out.println("i squared is " + i * i);
} %> --%>
A. Doesn't translate because the page source is incomplete.
B. Doesn't compile because nesting comments in this way is illegal.
C. The JSP page would compile if the terminating curly brace were removed.
D. The JSP page would compile if one of the percent (%) signs were removed.
E. Runs as is and produces output (possibly not the output intended).
D. <%@ page import='java.util.*, java.io.PrintStream'
import="java.text.*" %>
E. <%@page import = " java.util.* "%> correct answers 11. Which of the following
constitute valid ways of importing Java classes into JSP page source?
(Choose two.)
A. <%! import java.util.*; %>
B. <%@ import java.util.* %>
E. Web page returned showing a heading and the current date correct answers 1. What will be
the most likely outcome of attempting to access the following JSP for the second
time? (Choose one.)
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html><head><title>Chapter 6 Question 1</title></head>
<body>
<h1>Chapter 6 Question 1</h1>
<%!
public void jspInit() {
System.out.println("First half of jspInit()");
%>
<%> new Date() %>
<%!
System.out.println("Second half of jspInit()");
}
%>
</body></html>
A. Translation error (HTTP response code of 500)
B. Page not found error (HTTP response code of 404)
C. Web page returned showing a heading and the current date; two lines of output written to
the server log
D. Web page returned showing "First half of jspInit()," "Second half of jspInit()," a heading,
and the current date
E. Web page returned showing a heading and the current date
D. 3 correct answers 2. What is output to the web page on the second access to the same
instance of the following JSP?
(Choose one.)
<%@ page language="java" %>
<html>
<head><title>Chapter 6 Question 2</title></head>
<body>
<h1>Chapter 6 Question 2</h1>
<%! int x = 0; %>
<%!
public void jspInit() {
System.out.println(x++);
}
%>
<%= x++ %>
<% System.out.println(x); %>
<% jspInit(); %>
</body></html>
A. 0
B. 1
C. 2
D. 3
,E. 4
F. Page does not translate.
G. Page translates, but there is another runtime error.
A. Expression embedded in declaration. correct answers 3. For what reason does the
following JSP fail to translate and compile? (Choose one.)
<%@ page language="java" %>
<html>
<head><title>Chapter 6 Question 3</title></head>
<body>
<h1>Chapter 6 Question 3</h1>
<%! int x; %>
<%!
public void jspDestroy() {
System.out.println("self-destructing");
} %>
<%!
public void jspInit() {
System.out.println(<%= x %>);
}
%>
</body></html>
A. Expression embedded in declaration.
B. Data member x not initialized before use.
C. Local variable x not initialized before use.
D. Placement of jspDestroy() method before jspInit() method.
E. The page actually compiles and translates without any problem.
F. None of the above.
A. The _jspService() method is called from the generated servlet's service() method.
D. All servlet methods are accessible from the jspInit() method. correct answers 4. Which of
the following are true statements about the JavaServer Page life cycle?
(Choose two.)
A. The _jspService() method is called from the generated servlet's service() method.
B. jspInit() is only ever called on the fi rst request to a JSP instance.
C. jspDestroy() is only ever called on the last request to a JSP instance.
D. All servlet methods are accessible from the jspInit() method.
E. You cannot override or provide a no-parameter init() method in a JSP page.
A. Cannot resolve symbol compilation error.
E. Duplicate method compilation error. correct answers 5. What is the consequence of
attempting to access the following JSP page?
(Choose two.)
<%@ page language="java" %>
<html>
<head><title>Chapter 6 Question 5</title></head>
<body>
<h1>Chapter 6 Question 5</h1>
<%!public void _jspService(HttpServletRequest request,
HttpServletResponse response) {
,out.write("A");
} %>
<% out.write("B"); %>
</body>
</html>
A. Cannot resolve symbol compilation error.
B. "A" is output to the response.
C. "B" is output to the response.
D."A" is output to the response before "B."
E. Duplicate method compilation error.
F. "B" is output to the response before "A."
B. A translation error occurs. correct answers 6. What is the result of attempting to access the
following JSP page? (Choose one.)
<html>
<head><title>Chapter 6 Question 6</title></head>
<body>
<h1>Chapter 6 Question 6</h1>
<%! public String methodA() {
return methodB();
}
%>
<%! public String methodB() {
return methodC();
}
%>
<% public String methodC() {
return "Question 6 Text";
}
%>
<h2><%= methodA() %></h2>
</body>
</html>
A. "Question 6 Text" is output to the resulting web page.
B. A translation error occurs.
C. A runtime error occurs.
D. The text between the <h1></h1> HTML tags appears, followed by a Java stack
trace.
E. The web page is blank.
B. In JSP technology, it's a bad idea to get hold of the PrintWriter directly from the response.
H. The page has a compilation error for other reasons. correct answers 8. What true
statements can you make about the following JSP page source? The line
numbers are for reference only and should not be considered part of the source.
(Choose two.)
01 <%@ page import="java.io.*" %>
02 <html>
03 <head><title>Chapter 6 Question 8</title></head>
04 <body>
05 <%
, 06 PrintWriter out = response.getWriter();
07 out.write("P");
08 %>
09 <% out.write("Q"); %>
10 </body>
11 </html>
A. In line 09, the scriptlet markers should not be on the same line as the Java source
statement.
B. In JSP technology, it's a bad idea to get hold of the PrintWriter directly from the response.
C. "P" will be written to the response, followed by "Q."
D. "Q" will be written to the response, followed by "P."
E. Only "Q" will be written to the response.
F. The page has a compilation error because of a directive syntax error.
G. The page has a compilation error because the import in the directive syntax is for
the wrong Java package.
H. The page has a compilation error for other reasons.
A. It is legal to embed a <%--style comment inside another comment.
C. It is legal to embed an expression inside a declaration.
D. It is legal to embed an expression inside a directive. correct answers 9. Which of the
following are false statements to make about JSP scripting elements?
(Choose three.)
A. It is legal to embed a <%--style comment inside another comment.
B. It is legal to embed an expression inside a scriptlet.
C. It is legal to embed an expression inside a declaration.
D. It is legal to embed an expression inside a directive.
E. It is legal to include a declaration at any point in the JSP page source, provided that
it appears outside of other elements.
F. It is legal to embed a scriptlet inside an expression inside a <%--style comment.
D. The JSP page would compile if one of the percent (%) signs were removed. correct
answers 10. What is the result of attempting to access the following JSP page source?
(Choose one.)
<% <%-- for (int i = 0; i < 10; i++) {
<%-- if(i==3) System.out.println("i is 3!");--%>
System.out.println("i squared is " + i * i);
} %> --%>
A. Doesn't translate because the page source is incomplete.
B. Doesn't compile because nesting comments in this way is illegal.
C. The JSP page would compile if the terminating curly brace were removed.
D. The JSP page would compile if one of the percent (%) signs were removed.
E. Runs as is and produces output (possibly not the output intended).
D. <%@ page import='java.util.*, java.io.PrintStream'
import="java.text.*" %>
E. <%@page import = " java.util.* "%> correct answers 11. Which of the following
constitute valid ways of importing Java classes into JSP page source?
(Choose two.)
A. <%! import java.util.*; %>
B. <%@ import java.util.* %>