Você está na página 1de 35

QuestionNo: 1

Which of the following options enables you to obtain filter initialization parameters?
1, The FilterConfig reference
2, The ServletRequest reference
3, The ServletResponse reference
4, The FilterChain reference
Correct Ans: 1
QuestionNo: 2
The url-pattern element can be replaced with the _________ element to create a filter that applies
to a particular servlet.
1, filter-class
2, dispatcher
3, filter-name
4, servlet-name
Correct Ans: 4
QuestionNo: 3
Which of the following options does NOT hold true for DAO pattern?
1, Under the DAO pattern, you can reuse the data access code from other servlets.
2, Under the DAO pattern, you can make changes to back-end technologies independent of the
front-end technologies.
3, Under the DAO pattern, the Web tier communicates with the DAO classes.
4, Under the DAO pattern, the business services do not need to know how the data is stored.
Correct Ans: 3
QuestionNo: 4
Martin has created a Web application in which a servlet stores a JDBC URL as an attribute of the
session object to access a database. He wants other servlets of the application to retrieve the URL
attribute from the session object to access the database. Which of the following code snippets can
Martin use to retrieve the URL from the session object?
1, HttpSession session = request.getSession();
String url =(String)session.getAttribute("URL");
2, HttpSession session = request.getSession();
String url =session.getAttribute("URL");
3, String url =(String)session.getSession("URL");
4, HttpServletRequest session = request.getSession();
String url =(String)session.getAttribute("URL");
Correct Ans: 1

QuestionNo: 5
Mark has created a servlet named Registration. The servlet needs to be connected to the Students
database. Which of the following tasks is performed first to accomplish this task?
1, The component uses the JDBC API to communicate with the database by way of the
connection.
2, The component performs a JNDI lookup on the naming service to retrieve the DataSource.
3, The component calls the prepareStatement() method on the DataSource to retrieve a database
connection.
4, The component calls the getConnection() method on the DataSource to retrieve a database
connection.
Correct Ans: 2
QuestionNo: 6
Ronald has observed that his Web application has some HTML tags or features that all the Web
browsers do not support. If the client's browser does not support, the application may or may not
run, or may generate undesired output in the Web browser of the client. Therefore, Ronald wants
to identify the type of browser and other specific information about the client that sends the
request to the Web application before invoking the servlet. Which of the following options will
help Ronald provide this functionality?
1, By programming filters
2, By creating security constraints
3, By modifying the web deployment descriptor
4, By implementing the JSF technology
Correct Ans: 1
QuestionNo: 7
Which of the following options can be used by the controller to destroy a session of a web
application?
1, By using the invalidate() method
2, By setting the session-timeout parameter in the web.xml file
3, By using the setMaxInactiveInterval() method
4, By using the destroy() method
Correct Ans: 1
QuestionNo: 8
Wren has created a servlet that needs to be connected to a database. Wren decides to establish a
connection in a servlet, and then maintain that connection as a member variable of that servlet.
Which of the following drawbacks is Wren likely to face?
1, Performance problem
2, Threading problem
3, Maintenance problem
4, Speed problem
Correct Ans: 2

QuestionNo: 9
Jack Smith is working as a Java developer in P. Tech Ltd. He is developing a web application
using Servlets and JSP. He decides to use Filters in the web application. He has to ensure that the
filter would only be applied to internal dispatches to the URL pattern *.do and not to any direct
client requests. He uses the following code to declare the filter mapping:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
However, the above code make the auditFilter apply to the direct client requests for a URL which
matches *.do pattern. Identify the error and provide the solution.
1, Replace the code with the following:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>request</dispatcher>
</filter-mapping>
2, Replace the code with the following:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
3, Replace the code with the following:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>include</dispatcher>
</filter-mapping>
4, Replace the code with the following:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Correct Ans: 4

QuestionNo: 10
Jack Smith is working as a Java developer in P. Tech Ltd. He is developing a web application
using Servlets and JSP. He decides to use Filters in the web application. He has to ensure that the
filter would only be applied to direct client requests for a URL which matches the *.do pattern
and not to internal dispatches. He uses the following code to declare the filter mapping:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
However, the above code make the auditFilter apply to the internal dispatches for a URL which
matches *.do pattern. Identify the error and provide the solution.
1, Replace the code with the following:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
2, Replace the code with the following:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
3, Replace the code with the following:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
4, Replace the code with the following:
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
Correct Ans: 4

QuestionNo: 11
Jack Smith is working as a Java developer in P. Tech Ltd. He is developing a web application
using Servlets and JSP. He decides to use Filters in the web application. He uses the following
code to declare the filter in the application:
<filter>
<filter-name>perfFilter</filter-name>
<init-param>
<param-name>Log Entry Prefix</param-name>
<param-value>Performance: </param-value>
</init-param>
</filter>
However, the above code is incomplete in terms of filter declaration. Identify the error?
1, filter-class element is missing in the filter declaration.
2, servlet-name element is missing in the filter declaration.
3, servlet-mapping element is missing in the filter declaration.
4, url-pattern element is missing in the filter declaration.
Correct Ans: 1
QuestionNo: 12
Jack Smith is working as a Java developer in P. Tech Ltd. He is developing a web application
using Servlets and JSP. He decides to use Filters in the web application. He uses the following
code to declare the filter in the application:
<filter>
<filter-class>sl314.web.PerformanceFilter</filter-class>
<init-param>
<param-name>Log Entry Prefix</param-name>
<param-value>Performance: </param-value>
</init-param>
</filter>
Identify the error in the preceding code with respect to filters?
1, filter-name element is missing in the filter declaration.
2, servlet-name element is missing in the filter declaration.
3, servlet-mapping element is missing in the filter declaration.
4, url-pattern element is missing in the filter declaration.
Correct Ans: 1

QuestionNo: 13
Consider the code for filter mapping in the web application deployment descriptor file:
<servlet-mapping>
<servlet-name>MyController</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
1)<filter-mapping>
<filter-name>First</filter-name>
<servlet-name>MyController</servlet-name>
</filter-mapping>
2)<filter-mapping>
<filter-name>Second</filter-name>
<servlet-name>MyController</servlet-name>
</filter-mapping>
3) <filter-mapping>
<filter-name>Third</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
4)<filter-mapping>
<filter-name>Fourth</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
Predict the order in which filter will be applied if the request was made for the URL
/admin/add_league.do?
1,First>Second>Third>Fourth
2,Third>Fourth>First>Second
3,Fourth>Third>Second>First
4,Second>First>Fourth>Third
Correct Ans: 2
QuestionNo: 14
A code for filter mapping has to be written for a filter called Login Filter for components in such
a manner that it should be applied to component whenever an error occurs. Predict the code for
filter mapping to perform the required task from the following options.
1,<filter-mapping>
V<filter-name>LoginFilter</filter-name>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

2,<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
3,<filter-mapping>
<filter-name>LoginFilter</filter-name>
<dispatcher>ERROR</dispatcher>
<url-pattern>ERROR.do</url-pattern>
</filter-mapping>
4,<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>dispatcher.ERROR</dispatcher>
</filter-mapping>
Correct Ans: 2
QuestionNo: 15
Stem text : Consider the following code regarding accessing of session attributes in a
sessionmanagement program. But this program has few errors. Predict the correct code for the
program.
String login=request.getParameterValue("login");
if(login.equals("tim")
{
return mapping.Forward(error);
}
if(login.equals("David")
{
return mapping.Forward(success);
}
where mapping is an object of ActionMapping Class.
1,String login=request.getParameter("login");
if(login.equals("tim")
{
return mapping.Forward("error");
}
if(login.equals("David")
{
return mapping.Forward("success");
}

2,String login=request.getParameter("login");
if(login.equals("tim")
{
return mapping.findForward(error);
}
if(login.equals("David")
{
return mapping.findForward(success);
}
3,String login=request.getParameterValue("login");
if(login.equals("tim")
{
return mapping.findForward("error");
}
if(login.equals("David")
{
return mapping.findForward("success");
}
4,String login=request.getParameter("login");
if(login.equals("tim")
{
return mapping.findForward("error");
}
if(login.equals("David")
{
return mapping.findForward("success");
}
Correct Ans: 4
QuestionNo: 16
You have deployed two servlets named servlet1 and servlet2 in your Web server. You want to
create an attribute called "customernumber" and assign the value of a variable cnum to it. Which
of the following codes is the correct method for doing it?
1,ServletContext c=getServletContext();
c.setAttribute(cnum,"customernumber");
2,ServletConfig c=getServletConfig();
c.setAttribute(cnum,"customernumber");
3,ServletContext c=getServletContext()
c.setAttribute("customernumber", cnum)

4,ServletConfig c=getServletConfig();
c.setAttribute("customernumber", cnum);
Correct Ans: 3
QuestionNo: 17
Which method is used for destroying the HttpSession instance?
1,destroySession()
2,destroy()
3,invalidate()
4,close()
Correct Ans: 3
QuestionNo: 18
Which method of HttpSession interface is used for specifying the length of inactive interval for a
session object?
1,setMaxInterval()
2,setMaxInactiveInterval()
3,setMaxInactive_interval()
4,setInactiveInterval()
Correct Ans: 2
QuestionNo: 19
Which method can be used for adding cookies to the response object?
1,add()
2,addCookies()
3,addCookie()
4,addCookieList()
Correct Ans: 3
QuestionNo: 20
Which method of Filter interface is used to decide whether to call the next component in the
filter chain or incoming request has to be blocked?
1,service()
2,execute()
3,doFilter()
4,init()
Correct Ans: 3
QuestionNo: 21
Max is creating an application using the Struts framework. He has to develop the action form.
Which of the following options should he ensure while creating the action form?
1, The action form should not contain code to validate data.
2, The action form should not perform any data conversions.
3, The action form should not contain different names for the get and set methods from the
HTML form elements they represent.

4, The action form should not retrieve any data from the incoming request.
Correct Ans: 3
QuestionNo: 22
Harold has observed that some users are able to directly access the content files stored in the
Web application from the Web browser. Which of the following options should Harold use to
prevent the users from directly accessing the content files?
1, By storing the content files under the dist directory
2, By storing the content files under the META-INF directory
3, By storing the content files under the WEB-INF directory
4, By storing the content files under the INF directory
Correct Ans: 3
QuestionNo: 23
Thomas wants to implement the execute() method of the Action class in his controller class.
Which of the following tasks does he need to perform to use the accessor methods on the form
bean?
1, Thomas needs to write code to retrieve the form parameters.
2, Thomas needs to write code to convert the data.
3, Thomas needs to write code to perform verification.
4, Thomas needs to cast the generic ActionForm to his
application-specific class.
Correct Ans: 4
QuestionNo: 24
Angelina is creating an application using the Struts framework. The application consists of
multiple view pages. Now, Angelina needs to pass different values for the different view pages.
She decides to create layout files for the same. Which of the following options will help Angelina
perform the task quickly?
1, Create a layout file for each view page to pass the values for the respective view page.
2, Create a layout file and specify its location in the sunweb.xml file.
3, Create a layout file and specify its location in the strutsconfig.xml file.
4, Create a layout file using Tiles.
Correct Ans: 4
QuestionNo: 25
Predict the correct code for the declaration of a form bean called employeeform in the struts
framework?
1,import org.apache.struts.action.ActionForm;
public class employeeform implements ActionForm
{
//required code
}
2,import org.apache.struts.action.ActionForm;
public class employeeform extends ActionForm

{
//required code
}
3,import org.apache.struts.ActionForm;
public class employeeform extends ActionForm
{
//required code
}
4,import org.apache.struts.action.ActionForm;
public class employeeform
{
//required code
}
Correct Ans: 2
QuestionNo: 26
Harry wants to create a form bean in struts framework. He wants to perform certain validations
for that form bean. Which class he should use to create a form bean and which method he should
use to perform the validations for the form bean?
1,ActionForm Class & doValidate() method
2,Action Class & Validate() method
3,ActionForm Class & validate() method
4,ActionForm Class & performValidations() method
Correct Ans: 3
QuestionNo: 27
A Web application developed for an educational institution requires insertion of a header file
comprising the logo and institution name. Identify the correct JSP tag from the options given
below to add the logo and institution name to all the pages of the Web application.
1,<form method="post" action="Header.html">
2,<%@ include file="Header.html" %>
3,<jsp:forward page="Header.html">
4,<%@ page import="Header.html" %>
Correct Ans: 2
QuestionNo:28
Consider the following statements:
A) The doValidate() method is used to perform validation of Form Fields.
B) Struts provides a mechanism to store form data into a javabeans instance.
C) Data Conversion can be performed by the ActionForm Class.
D) The validate attribute in the action tag determines whether validation will occur for the form
bean or not.
Which of the following options is True with respect to the above statements?

1,Statement A,B,C are true and D is false.


2,Statement A is False and B,C,D are true.
3,Statement A,B are true and C,D are False.
4,Statement A,B,D are true and C is False.
Correct Ans: 2
QuestionNo: 29
Which of the following is NOT passed as an argument to the execute method of the Action class
in the Struts framework?
1, ActionMapping
2, HttpServlet
3, ActionForm
4, HttpServletRequest
Correct Ans: 2
QuestionNo: 30
What does the validate attribute in the action tag do?
1,Validates the user name and password
2,Determines whether validation will occur for the form bean
3,Authenticates the user to determine the permissions in an application
4,Performs the data conversion in an application
Correct Ans: 2
QuestionNo: 31
What is return type of validate method in struts framework?
1,ActionError
2,ActionErrors
3,ActionForward
4,ActionMapping
Correct Ans: 2
QuestionNo: 32
Which of the following is not the attribute taken by the Action Tag in the struts configuration
file?
1,name
2,scope
3,validate
4,invalidate
Correct Ans: 4

QuestionNo: 45
The web container maintains a pool of instances that is large enough to handle a number of
simultaneous ____________________.
1,Clients
2,Responses
3,Requests
4,Servers
Correct Ans: 3
QuestionNo: 46
_________________ creates a new request and response object for each new request that it
handles.
1,EJB Container
2,Servlet
3,Web Container
4,JSP Page
Correct Ans: 3
QuestionNo: 47
Which of the following programs runs in a separate thread in the Web container for each client
request?
1, HTML
2, Servlets
3, CGI
4, Pearl
Correct Ans: 2

QuestionNo: 48
You are creating a Web application. For this, you have to define various job roles in your Web
application team. One of the job roles requires creating View elements, such as HTML pages or
dynamically generated pages. Identify the job role.
1, Web Component Developer
2, Web Designer
3, Business Component Developer
4, Data Access Developer
Correct Ans: 2
QuestionNo: 49
You are creating a Web application. For this, you have to define various job roles in your Web
application team. One of the job roles requires creating Controller elements, which consist
mostly of servlets. Identify the job role.
1, Web Component Developer
2, Web Designer
3, Business Component Developer

4, Data Access Developer


Correct Ans: 1
QuestionNo: 50
Which method can be used to submit form data that should not be exposed for viewing?
1, PUT
2,GET
3,POST
4,REQUEST
Correct Ans: 3
QuestionNo: 51
You are creating a Web application. For this, you have to define various job roles in your Web
application team. One of the job roles requires creating Model elements that might exist on
the web tier as standard Java technology classes. Identify the job role.
1, Web Component Developer
2, Web Designer
3, Business Component Developer
4, Data Access Developer
Correct Ans: 3
QuestionNo: 52
HttpServletRequest is a sub interface of ____________.
1,HttpRequest
2,ServletRequest
3,HttpServlet
4,It is not a sub-interface
Correct Ans: 2
QuestionNo: 53
Whenever a request goes from the client to the server, some additional information other than the
request is also passed to the server. This additional information is in the form of a
____________.
1,footer
2,header
3,Application ID
4,Session ID
Correct Ans: 2
QuestionNo: 54
Which method of the HttpServlet class is implemented to filter incoming requests by type?
1,service
2,doGet
3,doPost
4,doPut

Correct Ans: 1
QuestionNo: 55
Which of the following action is not performed by servlets?
1,Retrieve form data
2,Retrieve security information
3,Generate output
4,Check compilation errors
Correct Ans: 4
QuestionNo: 56
Which of the following is Not the HTTP Request Header?
1,Accept
2,Host
3,Referer
4,Retrieve
Correct Ans: 4
QuestionNo: 57
Which method returns an enumeration of string composed of the names of each header in the
request stream?
1,getHeaderNames()
2,getHeaderInfo()
3,getHeader()
4,getHeaderName()
Correct Ans: 1

QuestionNo: 58
Servlets tie up files to independently handle the static presentation logic and the dynamic
business logic. Which files are used for handling presentation logic and business logic?
1,.html and .java
2,All the code can be written in a .html file
3,.html and.txt
4,.txt and .jsp
Correct Ans: 1
QuestionNo: 59
In the inter servlet communication, which method of the servlet API is used to store object
information in the Request Object?
1,setObject()
2,saveAttribute()
3,setAttribute()

4,saveObject()
Correct Ans: 3
QuestionNo: 60
Which of the following is NOT TRUE for the servlet ?
1,Servlets are Platform Independent.
2,Servlets are robust and object oriented.
3,Servlets only contains business logic.
4,Each request in servlet runs in separate thread.
Correct Ans: 3
QuestionNo: 61
Clara is developing the home page of a website using servlets. She wants the image in the
Welcome.jpg file to be displayed on the home page. Which of the following methods should
Clara use to generate the response?
1, getOutputStream()
2, getWriter()
3, setHeader()
4, getHeader()
Correct Ans: 1
QuestionNo: 62
Predict the output of the following code:
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class earnmore extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException
{
String pageTitle = "Welcome to EarnMore Bank";
response.setContentType("text/html");
out.println("<html>");
out.println("<body>");
out.println(pageTitle);
out.println("</body>");
out.println("</html>");
}
}
1, The code will compile and execute successfully. The string, Welcome to EarnMore Bank, will
be displayed.

2, The code will compile successfully but give a runtime error.


3, The code will display a blank page.
4, The code will give compilation error.
Correct Ans: 4
QuestionNo: 63
Jennifer has created an HTML form that accepts two numbers from the user. This form contains
a button. When this button is clicked, the numbers are passed to a servlet. Jennifer creates a
servlet named Calculate to calculate the sum of the numbers entered by the user. She, then,
creates another servlet named Display to display this sum. Now, she wants the sum calculated by
the Calculate servlet to be passed to the Display servlet. The code of the Calculate servlet is:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Calculate extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
int num1=Integer.parseInt(request.getParameter("number1"));
int num2=Integer.parseInt(request.getParameter("number2"));
int result= num1+num2; }
}
Which of the following code snippets will help Jennifer use to provide the required
functionality?
1, request.setAttribute("result",new Integer(result));
RequestDispatcher reqDisp=request.getRequestDispatcher("/Display");
reqDisp.forward(request,response);
2, RequestDispatcher reqDisp=request.getRequestDispatcher("/Display");
reqDisp.forward(request,response);
3, request.setAttribute("result",new Integer(result));
RequestDispatcher reqDisp=request.getRequestDispatcher("Display");
reqDisp.forward(request,response);
4, response.setAttribute("result",new Integer(result));
RequestDispatcher reqDisp=request.getRequestDispatcher("Display");
reqDisp.forward(request,response);
Correct Ans: 3
QuestionNo: 64
Michelle has created the Hello servlet that displays Welcome in the browser window. The code
of the servlet is:
package myworld;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class hello extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>My Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>WELCOME</h1>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
Which of the following code snippets correctly defines the deployment descriptor for the
preceding servlet?
1, <servlet>
<servlet-name>hello</servlet-name>
<servlet-class>hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
2, <servlet>
<servlet-name>hello</servlet-name>
<servlet-class>myworld.hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
3, <servlet>
<servlet-name>myworld.hello</servlet-name>
<servlet-class>hello</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
4, <servlet>
<servlet-name>hello</servlet-name>
<servlet-class>myworld.hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>hello</url-pattern>
</servlet-mapping>
Correct Ans: 2
QuestionNo: 65
Paul has created a bean called myclass that wraps a collection of student objects. He has written
the following code snippet to iterate over the myclass bean and produce one row for each
student:
<c:forEach var="student" items="${myclass.myclass}">
<tr>
<td>${student.name}</td>
<td>${student.age}</td>
<td>${student.height}</td>
</tr>
</c:forEach>
Now, Paul wants to write the preceding code snippet using scriptlets and unordered list. Which of
the following code snippets fulfills Paul's requirement?

1, <ul>
<%
Iterator items = myclass.iterator();
while ( items.hasNext() ) {
myclass myclass1 = (myclass) items.next();
%>
<li><%= student.getTitle() %></li>
<% } %>
</ul>
2, <ul>
<%
Iterator items = myclass.iterator();

while ( items.hasNext() ) {
myclass myclass1 = items.next();
%>
<li><%= student.getTitle() %></li>
<% } %>
</ul>
3, <ul>
<%
Iterator items = myclass.iterator();
myclass myclass1 = (myclass) items.next();
%>
<li><%= student.getTitle() %></li>
<% } %>
</ul>
4, <ul>
<%
Iterator items = myclass.iterator();
while ( items.hasNext() ) {
myclass myclass1 = (myclass) items.next();
%>
<li><%= myclass.getTitle() %></li>
<% } %>
</ul>
Correct Ans: 1

zQuestionNo: 66
Linda has created a servlet that accepts the name, phone number, address, and educational
qualifications of the user. The servlet contains text fields to enter the name, phone number, and
address. It contains a drop-down list from which the user can select the qualifications. Linda
wants the drop-down list to be populated with the values, 10+2, graduation, and post graduation
after the servlet instance is created. In which of the following methods should Linda place the
code to populate the drop-down list?
1, getServletConfig()
2, getParameter()
3, service()
4, init()
Correct Ans: 4
QuestionNo: 67

Which of the following lines of code can be used for adding a pre-defined applet named chatApp
to a JSP page?
The chatApp class file is present in the /applets directory.
1,<jsp:plugin type="applet" code="chatApp.class" codebase="/applets" width="400"
height = "300">
</jsp:plugin>
2,<jsp:plugin type="applet" code="chatApp.class" codebase="applets" width="400" height =
"300"">
</jsp:plugin>
3,<jsp:plugin type="applet" code="chatApp.class" codebase="/applets" width="400" height =
"300"/>
4,<jsp:plugin code="chatApp.class" codebase="/applets" width="400" height = "300>
</jsp:plugin>
Correct Ans: 1
QuestionNo: 68
What will be the output of the following code snippet:
<%@ page language="java"%>
<html>
<head></head>
<body>
<%java.util.Date now=new java.util.Date(); %>
<H1><%= now.getHours() %>:<%=now.getMinutes()%>:<%=now.getSeconds()%></H1>
</body>
</html>
1,It will display the date as mm:dd:yy.
2,It will display the date and time.
3,It will display time as hh/mm/ss.
4,It will display the current time as hh:mm:ss.
Correct Ans: 4
QuestionNo: 69
What will be the output of the following code snippet:
<%@ page language="java"%>
<html>
<head></head>
<body>
<%java.util.Date now=new java.util.Date(); %>
<H1><%= now %></H1>
</body></html>
1,It will display the date and time.
2,It will display the time and day of the week.
3,It will display the date and day of the week.
4,It will display the date, time, and day of the week.
Correct Ans: 4

QuestionNo: 70
Consider the following code:
<%@ page language="java"%>
<html>
<body>
<% String login=(request.getParameter("Login"));
String password=(request.getParameter("Password"));
for(int i=0;i<10;i++)
out.println("Login is"+" "+login);
out.println("Password is"+" "+password);
%>
</body>
</html>
What will be the output of the above code if login name and password are accepted through user
interface?
1,Login message will be displayed ten times and Password message once.
2,Both login and password message will be displayed ten times.
3,Login Message will be displayed nine times and Password message once.
4,Both login and password message will be displayed nine times.
Correct Ans: 1
QuestionNo: 71
Consider the usage of JSTL forEach tag in the following code snippet:
<font color='green'>
<ul>
<c:foreach flag=errmsg items="${errorMsgs}">
<li>$errmsg</li>
</c:forEach>
</ul>
</font>
However, the preceding code snippet contains some errors. Predict the correct code.
1,<font color='green'>
<ul>
<c:forEach var=errmsg items="${errorMsgs}">
<li>$errmsg</li>
</c:forEach>
</ul>
</font>
2,<font color='green'>
<ul>

<c:forEach var="errmsg" items="${errorMsgs}">


<li>${errmsg}</li>
</c:forEach>
</ul>
</font>
3,<font color='green'>
<ul>
<c:forEach var="errmsg" items="${errorMsgs}">
<li>$errmsg</li>
</c:forEach>
</ul>
</font>
4,<font color='green'>
<ul>
<c:forEach var=errmsg items="${errorMsgs}">
<li>${errmsg}</li>
</c:forEach>
</ul>
</font>
Correct Ans: 2
QuestionNo: 72
Consider following statements for Expression Tag in JSP:
A) An Expression tag can take any java language expression that can be used as an argument
to System.out.println.
B) Expression tag is evaluated during HTTP Response.
C) The Result of the Expression tag is included in HTTP request stream.
D)After Evaluation, the value of Expression tag has to be converted to a String.
Which of the following options is True with respect to the above statements?
1,Statement A,B, and C are true.
2,Statement A and D are true.
3,Statement B,C, and D are true.
4,Statement A,B, and D are true.
Correct Ans: 2
QuestionNo: 73
Consider the following code snippet of JSP Bean:
<jsp:usebean identity="login" scope="Session" class=s1314.beans.LoginBean>
<%!
login.setValue(request.getParameter("Loginid"));
login.setAddress(request.getParameter("address"));
%>
<jsp:usebean>

However, the preceding code contains errors. Predict the correct code.
1,<jsp:useBean id="login" scope="Session" class="s1314.beans.LoginBean">
<%
login.setValue(request.getParameter("Loginid"));
login.setAddress(request.getParameter("address"));
%>
</jsp:useBean>
2,<jsp:useBean identity="login" scope="Session" class="s1314.beans.LoginBean">
<%!
login.setValue(request.getParameter("Loginid"));
login.setAddress(request.getParameter("address"));
%>
<jsp:useBean>
3,<jsp:useBean id="login" scope="Session" class="s1314.beans.LoginBean">
login.setValue(request.getParameter("Loginid"));
login.setAddress(request.getParameter("address"));
</jsp:useBean>
4,<jsp:useBean id="login" scope="Session" class="s1314.beans.LoginBean">
<login.setValue(request.getParameter("Loginid"));/>
<login.setAddress(request.getParameter("address"));/>
</jsp:useBean>
Correct Ans: 1
QuestionNo: 74
While configuring the JSP Environment, you want to turn off scripting as well as ignore EL in
the JSP file. What would be the code for this?
1,<jsp-config>
<jsp-property-group>
<url-pattern>/scriptting_off/*</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
<jsp-property-group>
<url-pattern>/EL_off/*</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>
2,<jsp-property-group>
<url-pattern>/scriptting_off/*</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
<jsp-property-group>
<url-pattern>/EL_off/*</url-pattern>
<el_ignored>true</el_ignored>

</jsp-property-group>
3,<jsp-config>
<url-pattern>/scriptting_off/*</url-pattern>
<scripting-invalid>true</scripting-invalid>
<url-pattern>/EL_off/*</url-pattern>
<el_ignored>true</el_ignored>
</jsp-config>
4,<jsp-config>
<jsp-property-group>
<url-pattern>scriptting_off</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
<jsp-property-group>
<url-pattern>EL_off</url-pattern>
<el_ignored>true</el_ignored>
</jsp-property-group>
</jsp-config> >
Correct Ans: 1
QuestionNo: 75
Which method does the servlet API use to get the servlet's initialization parameters?
1,initParameter
2,getInit
3,getInitParameter
4,getParameter
Correct Ans: 3
QuestionNo: 76
Which of the following methods of the GenericServlet abstract class takes request and response
objects as arguments?
1, init
2, service
3, destroy
4, getServletContext
Correct Ans: 2
QuestionNo: 77
Once the usage of the web component is over, the web container removes the web component.
Which method is called by the web container before it removes the instance of the web
component?
1,delete
2,remove
3,service
4,destroy

Correct Ans: 4
QuestionNo: 78
Which of the following is the correct sequence of life cycle of a servlet?
1,init()
service()
destroy()
2,init()
start()
destroy()
3,service()
init()
destroy()
4,start()
service()
destroy()
Correct Ans: 1
QuestionNo: 79
Which function of ServletConfig interface is used to retrieve servlet initialization parameters?
1,getInitParameter()
2,getInitParameters()
3,getInitialParameters()
4,getParameters()
Correct Ans: 1
QuestionNo: 80
What is the syntax of Expression Language in a JSP page?
1,${expr}
2,#{expr}
3,${"expr"}
4,$[expr]
Correct Ans: 1
QuestionNo: 81
Which attribute of page directive is used for specifying the name of another jsp page that will
handle all run time exceptions?
1,err
2,errorPage
3,error_page
4,runtimeerrorpage
Correct Ans: 2

QuestionNo: 82
Which attribute of page directive is used for specifying the superclass of servlet class that is
generated from the jsp page?
1,jsp:extends
2,implements
3,extends
4,jspextends
Correct Ans: 3
QuestionNo: 83
Which method of jsp is equivalent to service method of servlet?
1,_jspService()
2,jsp_Service()
3,jspService()
4,service()
Correct Ans: 1
QuestionNo: 84
Sam is writing a web application program. He has implemented ServletContextListener interface
in his web application program. Which method of ServletContextListener interface he should use
to perform startup activities for web application?
1,init()
2,initiateContext()
3,contextInitialized()
4,start()
Correct Ans: 3

QuestionNo: 85
Sam is writing a web application program. He has implemented ServletContextListener
interface in his web application program. Which method of ServletContextListener Interface he
should use to perform some cleanup activities for web application?
1,destroy()
2,contextDestroy()
3,close()
4,contextDestroyed()
Correct Ans: 4
QuestionNo: 86
List down the methods of ServletContext Interface.
1,getInitParameter(name:String):String

getInitParameterNames():Enumeration
getResource(path):URL
getResourceAsStream(path):InputStream
2,getInitParameter(name:String):String
getInitParameterList():Enumeration
getResourceUrl(path):URL
getResourceAsStream(path):InputStream
3,getInitParameter():String
getInitParametervalues():Enumeration
getResource(path):URL
getResourceAsStream(path):void
4,getInitParameter(name:String):String
getInitParameterList():Enumeration
getResourceAsInputStream(path):InputStream
Correct Ans: 1
QuestionNo: 87
Margaret is developing a Web application for a travel agency. She creates a servlet with the
initialization parameter, holiday_destination. Based on the values of the initialization parameter,
the servlet displays the relevant information. Margaret now wants to retrieve the value of the
initialization parameter. Which of the following code snippets helps retrieve the initialization
parameter successfully?
1, public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException
{
String strValue=getInitParameter("holiday_destination");
}
2, public void init() throws ServletException
{
String strValue=getInitParameter("holiday_destination");
}
3, public void doPost(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
{
String strValue=getInitParameter("holiday_destination");
}
4, public void init() throws ServletException
{
String strValue=request.getInitParameter("holiday_destination");

}
Correct Ans: 2
QuestionNo: 88
Samantha is developing an online book store. She creates a JavaBean that accepts and stores the
book preferences of a user in the array, userpref. Now, Samantha wants to develop a servlet that
retrieves the book preferences from the JavaBean. Which of the following code snippets will
help her retrieve the third element of the userpref array?
1, ${param.userpref[2]}
2, ${paramValues.userpref[3]}
3, {paramValues.userpref[2]}
4, ${paramValues.userpref[2]}
Correct Ans: 4
QuestionNo: 89
George is developing an application for an airline service. During the development of the
application, he is faced with the problem of coupling between view and controller components.
In addition, he finds that a lot of common infrastructure processing is being used in the
controllers of the application. He wants to avoid scripting the same code repeatedly. Which of the
following patterns will help George resolve these problems?
1, Value Object pattern
2, MVC pattern
3, DAO pattern
4, Front Controller pattern
Correct Ans: 4

QuestionNo: 90
Mark is developing an application using the Struts MVC framework. He wants to configure the
mappings between URL patterns and the controller classes. Which of the following options will
help Mark in this task?
1, Base classes
2, The strutsconfig.xml file
3, The ActionServlet class
4, The Action class
Correct Ans: 3
QuestionNo: 91

You are creating an application using Struts framework. Now, you have to install the Struts
library files. You want to install a library that provides XML parsing utilities. Which of the
following libraries will you install?
1, struts.jar
2, commons-beanutils.jar
3, commons-digester.jar
4, struts.war
Correct Ans: 3
QuestionNo: 92
Leander is developing an application using the Struts framework. He has created an action class
that accepts name and password as input from the user. If the password contains eight characters,
a login-id is created and displayed to the user. Otherwise, an error page needs to be displayed.
Which of the following methods should Leander use to invoke the error page in case of an
incorrect user input.
1, getRequestDispatcher() method
2, findForward() method
3, forward() method
4, execute() method
Correct Ans: 2
QuestionNo: 93
Sam is software developer at DreamSoft Technologies. His team is developing a Web application
for an institute, which provides online classes to the engineering students. In this Web
application, the team members have created three services, StudentService, BatchService, and
BatchAllocationService. The BatchAllocationService interacts with the StudentService and
BatchService to allocate a batch to a student. However, the team members find that there is a
tight coupling between the three services in the application. To reduce coupling, Sam decides to
use the Struts framework in the application. Analyze the scenario and predict whether Sam will
be able to reduce coupling. If not, provide the solution.
1, No, Sam should use the Faade Service in the application.
2, Yes, Sam will be able to reduce coupling by using the Struts framework in the application.
3, No, Sam should use EJB in the application.
4, No, Sam should use entity service in the application.
Correct Ans: 1

QuestionNo: 94
Mark is developing a shopping site for Nucleus Inc., using the Struts framework. He has to write
the code to track the items that a user adds to the shopping cart. To implement this functionality,
he writes the following code in the AddItemsAction class:

public class AddItemsAction extends Action


{
public ActionForward execute(ActionForm form, HttpServletRequest request,
HttpServletResponse response)
{
List errorMsgs = new LinkedList();
request.setAttribute("errorMsgs", errorMsgs);
try
{
String itemStr = request.getParameter("Item").trim();
String itemCode = request.getParameter("Code").trim();
..........
..........
}
catch(Exception E)
{
E.printStackTrace()
}
}
}
However, the preceding code causes errors during compilation. Analyze the preceding code to
identify the cause of error and provide the solution.
1, The setAttribute() method is used incorrectly in the code. The correct code is:
response.setAttribute("errorMsgs", errorMsgs);
2, The setAttribute() method is used incorrectly in the code. The correct code is:
request.setAttribute(errorMsgs, "errorMsgs");
3, The incorrect signature of the execute() method is used in the code. The correct signature is:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletResponse
response)
4, The incorrect signature of the execute() method is used in the code. The correct signature
is:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
Correct Ans: 4

QuestionNo: 95
Jenny has been assigned the task to develop a login module of a Web application that
authenticates the users and provides success and failure messages depending upon the user
credentials. The two types of users of the Web application are provider and consumer. As, the

Web application has been developed using the Struts framework, Jenny creates two action
classes to validate the users. The ValidateProvideAction class validates the users who log in as
provider. However, the ValidateConsumerAction class the users who log in as consumer. She
stores the two action classes in the validate package of the application. After creating the action
classes, she writes the following code in the struts-config.xml file to configure the action classes:
<action-mappings>
<action path="/StrutsApp/form" type="/ValidateProvideAction">
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
<action path="/StrutsApp/form" type="/ValidateConsumerAction">
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
</action-mappings>
However, Jenny is not able to perform the desired task with the preceding mapping. Identify the
correct code that Jenny can use to perform the desired task.
1, <action-mappings>
<action path="/StutsApp/form" type="validate.ValidateProvideAction">
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
<action path="/StrutsApp/form" type=" validate.ValidateConsumerAction ">
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
</action-mappings>
2, <action-mappings>
<action path="/StutsApp/form" type="validate/ValidateProvideAction">
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
<action path="/StrutsApp/form" type=" validate/ValidateConsumerAction ">
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
</action-mappings>
3, <action-mappings>
<action path="/StutsApp/form" type="/validate/ValidateProvideAction">
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>

<action path="/StrutsApp/form" type=" /validate/ValidateConsumerAction ">


<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
</action-mappings>
4, <action-mappings>
<action path="/StutsApp/form" type=validate.ValidateProvideAction>
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
<action path="/StrutsApp/form" type= validate.ValidateConsumerAction >
<forward name="success" path="/webpage/success.view"/>
<forward name="error" path="/webpage/error.view"/>
</action>
</action-mappings>
Correct Ans: 1
QuestionNo: 96
Robin is developing a Web application by using the Struts framework. He stores the application
in a folder named StrutsApp. Moreover, he creates the lib folder in the StrutsApp folder and
stores the struts.jar, commons-beanutils.jar, and commons-digester.jar files in the lib folder.
However, he is not able to execute the application successfully. Identify the problem and provide
the solution.
1, Robin should move the lib folder to the src folder of the application.
2, Robin should move the lib folder to the web folder of the application.
3, Robin should move the lib folder to the WEB-INF folder of the application.
4, Robin should move the lib folder to the classes folder of the application.
Correct Ans: 3
QuestionNo: 97
You have been assigned the task of designing the web application for the Library of your
organization. The web application is divided into three components: Boundary, Service and
Entity. You are required to reduce the coupling between the boundary components and other
services while designing the communication between them in the web application. How will you
perform this task?
1, By using the Entity related services.
2, By using the Facade service.
3, By using Domain Entities.
4, By using the Analysis model.
Correct Ans: 2
QuestionNo: 98

You are developing a web application for the soccer league using Struts framework. For this, you
need to create a Struts controller that extends the Struts Action base class and implements the
execute method. How will you declare the execute method in the Struts controller class?
1, public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
//write the code
}
2, public void execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response)
{
//write the code
}
3, public int execute(ActionMapping mapping, HttpServletRequest request, HttpServletResponse
response)
{
//write the code
}
4, public ActionForward execute(ActionForm form, HttpServletRequest request,
HttpServletResponse response)
{
//write the code
}
Correct Ans: 1
QuestionNo: 99
You are developing a web application for the soccer league using servlets. You decided to use the
Struts framework to develop the web application. For this, you need to create a Struts controller.
How will you create the Struts controller class?
1, By extending the Struts Action class
2, By extending the Struts ActionForward class
3, By extending the Struts ActionMapping class
4, By extending the Struts ActionForm class
Correct Ans: 1
QuestionNo: 100
You are developing a web application using Servlets. You decide to use Struts framework to
develop the web application. For this, you are required to first configure the Struts Infrastructure
Controller. What will you do to configure the Struts Infrastructure Controller?
1, Configure the action mappings.
2, Install the Struts library files.
3, Configure the Struts ActionServlet in the deployment descriptor file.
4, Configure application-specific classes.

Correct Ans: 3
QuestionNo: 101
Which component is used for implementing communication between the entity and boundary
component?
1,service
2,view
3,controller
4,external entity
Correct Ans: 1
QuestionNo: 102
Which package is used for implementing struts framework in a program?
1,org.apache.strutsframework.action
2,org.apache.struts.action
3,org.apache
4,org.apach_struts
Correct Ans: 2
QuestionNo: 103
The return type of the execute method in struts framework is ___________.
1, ActionForm
2,ActionForward
3,ActionMapping
4,Action
Correct Ans: 2
QuestionNo: 104
What is the primary Struts Framework Library file?
1,struts.jar
2,struts_lib.jar
3,strutslib.jar
4,struts_primary.jar
Correct Ans: 1

Você também pode gostar