What will be the output of the following JSP code? <html><body> <%! int a = 20; %> <% int a = 10; %> <%! int b = 30; %> Now b = <%= b * a %> </body></html>
A Now b = 300
B Now b = 600
C The code will not compile
D Now b = 30
E Now b = 0
Answer
B
Consider the following code snippet of servlet code:
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String value = getValue ();
if (value == null) response.sendError (HttpServletResponse.SC_NOT_FOUND, "Failed");
response.sendRedirect ("test.jsp");
}
If the getValue () method returns null , which of the following statements are true?
A The code will work without any errors or exceptions B An IllegalStateException will be thrown
C An IOException will be thrown
D A NullPointerException will be thrown
Answer
B
Which of the following statements is true regarding MyServlet?
import javax.servlet.*;
import javax.servlet.http.*:
import java.io.*;
public class MyServlet extends HttpServlet implements SingleThreadModel
{
String myName;
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter out = res.getWriter();
myName = req.getParameter("name");
sayHello(out);
out.close();
}
public void sayHello(PrintWriter out) {
out.println("Hello " + myName);
}
}
A MyServlet is thread safe
B MyServlet is not thread safe because myName is an instance variable
C MyServlet is not thread safe because MyServlet implements SingleThreadModel.
D None of the above
Answer
A
Which of the following combinations regarding Design Patterns are correct?
A Business Delegate - Reduces the coupling between presentation-tier clients and business services.
B Data Access Object - Allows for Multiple Views using the same model
C MVC - Enables easier migration to different persistence storage implementations.
D Value Object - Reduces Network Traffic
Answer
A and D
Which of these is true about deployment descriptors. Select one correct answer.
A The order of elements in deployment descriptor is important. The elements must follow a specific order.
B The elements of deployment descriptor are not case insensitive
C The servlet-mapping element, if defined, must be included within the servlet element.
D The web-app element must include the servlet element
Answer
A
Which element of the deployment descriptor includes the exception-type as a sub-element ?
A <exception>
B <error-page>
C <error>
D <exception_type>
E <error_page>
Answer
B
Which of these is a correct fragment within the web-app element of deployment descriptor. Select the two correct answer.
A <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
B <error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
C <error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> </error-page>
D <error-page> <exception-type>mypackage.MyException</exception-type> <location>/error.jsp</location> </error-page>
Answer
A and D
Which element of the deployment descriptor of a web application includes the welcome-file-list element as a sub element.
A <welcome>
B <welcome-files>
C <list>
D <web-app>
E <context>
Answer
D
Which of these is a correct example of specifying a listener element resented by MyClass class. Assume myServlet element is defined correctly. Select one correct answer.
A <listener>MyClass</listener>
B <listener> <listener-class>MyClass</listener-class></listener>
C <listener> <listener-name>aListener</listener-name> <listener-class>MyClass</listener-class> </listener>
D <><listener> <servlet-name>myServlet</servlet-name> <listener-class>MyClass</listener-class> </listener>
Answer
B
Which of the following is legal JSP syntax to print the value of i. Select the one correct answer
A <<%int i = 1;%>
<%= i; %>
B <%int i = 1;
i; %>
C <%int i = 1%>
<%= i %>
D <%int i = 1;%>
<%= i %>
E <%int i = 1%>
<%= i; %>
Answer
D