NEW
Font size
WorksheetsPRJ301 FPT kì 4
Total questions: 70
Worksheet time: 35mins
Which of the following statements are correct about the status of the Http response? Select the one correct answer
A. A status of 200 to 299 signifies that the request was successful.
B. A status of 300 to 399 is informational messages.
C. A status of 400 to 499 indicates an error in the server
D. A status of 500 to 599 indicates an error in the client.
Servlet methods are executed automatically.
A. True
B. False
If you want the same servlet to handle both GET and POST and to take the same action for each, you can simply have doGet call doPost, or vice versa.
A. True
B. False
When a web server responds to a request from a browser or other Web client the response typically consists of: (Choose one)
A. a status line, some response headers, a blank line, and the document
B. a status line, a blank line, and the document
C. a blank line, a status line, some response headers and the document
D. a status line, some response headers, and the document
Which of these is legal return type of the doStartTag method defined in a class that extends TagSupport class?
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_INCLUDE
D. EVAL_BODY_INCLUDE
E. SKIP_PAGE
Classes HttpServlet and GenericServlet implement the ___ interface.
A. Servlet
B. Http
C. HttpServletRequest
D. HttpServletResponse
You have to send a gif image to the client as a response to a request. Which of the following calls will you have to make?
A. response.setContentType("image/gif");
B. response.setType("application/gif");
C. response.setContentType("application/bin");
D. response.setType("image/gif");
Consider the code of ReportServlet servlet of a web application. Assuming generateReport() is valid method and have no problems, which of the following statement about these servlet is true?
A. ReportServlet will throw exception at runtime.
B. ReportServlet.java won't compile.
C. ReportServlet.java will compile and run without any problems
Which method of ReportGeneratorServlet will be called when the user clicks on the URL shown by the following HTML.
Assume that ReportGeneratorServlet does not override the service(HttpServletRequest, HttpServletResponse) method of the HttpServlet class.
(Choose one)
A. doGet(HttpServletRequest, HttpServletResponse);
B. doPost(HttpServletRequest, HttpServletResponse);
C. doHead(HttpServletRequest, HttpServletResponse);
D. doOption(HttpServletRequest, HttpServletResponse);
What will be the outcome of executing the following code?
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
response.setContentLength(6);
PrintWriter out = response.getWriter();
out.write("What's your name? ");
out.write("" + response.isCommitted());
}
A. Won't execute because of a compilation error.
B. An IllegalArgumentException is thrown.
C. An IllegalStateException is thrown.
D. A blank page is returned to the client.
F. "What's your name?" is returned to the client.
E. "What's" is returned to the client.
Following is the code for doGet() and doPost() methods of TestServlet.
Which of the statement is correct?
A. This will only work for HTTP GET requests
B. This will only work for HTTP POST requests
C. This will work for HTTP GET as well as POST requests.
D. It'll throw an exception at runtime, as you cannot call doGet() from doPost().
E. It'll throw an exception at runtime only if a POST request is sent to it.
Which of the following is indicated by URL, which is used on the Internet?
A. Information resources(sources) on the Internet
B. E-mail addresses for use in the Internet
C. IP addresses of servers connected to the Internet
D. Owners of PCs connected to the Internet
See the extract from web.xml of web application "mywebapp" on server named myserver, runs on port 8080:
<servlet-mapping>
<servlet-name>ServletA</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletB</servlet-name>
<url-pattern>/bservlet.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletC</servlet-name>
<url-pattern>*.servletC</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletD</servlet-name>
<url-pattern>/dservlet/*</url-pattern>
</servlet-mapping>
Given that a user enters the following into her browser, which (if any) of the mapped servlets will execute? (Choose one.)
http://myserver:8080/mywebapp
A. ServletA
B. ServletB
C. ServletC
D. ServletD
A parameter is defined in a <context-param> element of the deployment descriptor for a web application. Which of the following statements is correct?
A. It is accessible to all the servlets of the webapp.
B. It is accessible to all the servlets of all the webapps of the container.
C. It is accessible only to the servlet it is defined for.
A .................... manages the threading for the servlets and JSPs and provides the necessary interface with the Web server.
A. Web Container
B. EJB Container
C. Servlets
D. Applets
A ________has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.
A. Cookie
B. Session
C. Request
D. Response
Which of the following method calls can be used to retrieve an object from the session that was stored using the name "roleName"?
A. getObject("roleName");
B. getValue("roleName");
C. get("roleName");
D. getAttribute("roleName");
E. getParameter("roleName");
Which is NOT a standard technique for a session be definitely invalidated?
A. The container is shutdown and brought up again.
B. No request comes from the client for more than "session timeout" period.
C. A servlet explicitly calls invalidate() on a session object.
D. If the session time out is set to 0 using setMaxInactiveInterval() method.
Which method can be invoked on a session object so that it is never invalidated by the servlet container automatically?
A. setMaxInactiveInterval(-1)
B. setTimeOut(Integer.MAX_INT)
C. setMaxInactiveInterval(Integer.MAX_INT)
D. setTimeOut(-1)
Session death is more likely to come about through a time-out mechanism. If there is no activity on a session for a predefined length of time, the web container invalidates the session.
A. True
B. False
A. True
B. False
A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/Final/test.jsp?name=John. The test.jsp contains the following code.
<% String myName=request.getParameter("name");%>
<% String test= "Welcome " + myName; %>
<%=test%>
What is the output?
A. The page display "Welcome John"
B. The program gives a syntax error because of the statement
<% String myName=request.getParameter("name");%>
C. The program gives a syntax error because of the statement
<% String test= "Welcome " + myName; %>
D. The program gives a syntax error because of the statement
<%=test%>
Name the default value of the scope attribute of <jsp:useBean>
A. page
B. session
C. application
D. request
A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/test.jsp?name="John". The test.jsp contains the following code.
<%! String myName=request.getParameter();%>
<% String test= "welcome" + myName; %>
<%= test%>
What is the output?
A. The program prints "Welcome John"
B. The program gives a syntax error because of the statement <%! String myName=request.getParameter();%>
C. The program gives a syntax error because of the statement <% String test= "welcome" + myName; %>
Select the correct directive statement insert into the first line of following lines of code (1 insert code here):
B. <%@import package='java.util.*' %>
C. <%@ package import ='java.util.*' %>
D. <%! page import='java.util.*' %>
A. <%@page import='java.util.*' %>
For JSP scopes of request and page, what type of object is used to store the attributes?
A. HttpServletRequest and ServletContext respectively.
B. ServletRequest and ServletConfig respectively.
C. ServletRequest and PageContext respectively.
D. HttpServletRequest and PageContext respectively.
E. ServletConfig for both.
Which of the following correctly represents the following JSP statement? Select one correct answer.
<%=x%>
A. <jsp:expression=x/>
B. <jsp:expression>x</jsp:expression>
C. <jsp:statement>x</jsp:statement>
D. <jsp:declaration>x</jsp:declaration>
E. <jsp:scriptlet>x</jsp:scriptlet>
Which technique is likely to return an initialization parameter for a JSP page?
A. <%= request.getParameter("myParm") %>
B. <% String s = getInitParameter("myParm"); %>
C. <% = application.getInitParameter("myParm") %>
D. <%= getParameter("myParm") %>
E. <% String s = getAttribute("myParm"); %>
A JSP ________________ lets you define methods or fields that get inserted into the main body of the servlet class (outside of the _jspService method that is called by service to process the request).
A. declaration
B. scriptlet
C. expression
Which jsp tag can be used to set bean property?
A. jsp:useBean
B. jsp:useBean.property
C. jsp:useBean.setProperty
D. jsp:property
E. jsp:setProperty
Which statements are BEST describe param attribute of <jsp:setProperty param=.... /> Action?
A. The ID of the JavaBean for which a property (or properties) will be set.
B. The name of the property to set. Specifying "*" for this attribute causes the JSP to match the request parameters to the properties of the bean.
C. If request parameter names do not match bean property names, this attribute can be used to specify which request parameter should be used to obtain the value for a specific bean property.
D. The value to assign to a bean property. The value typically is the result of a JSP expression.
hich statements are BEST describe value attribute of <jsp:setProperty value=... /> action?
A. The ID of the JavaBean for which a property (or properties) will be set.
B. The name of the property to set. Specifying "*" for this attribute causes the JSP to match the request parameters to the properties of the bean.
C. If request parameter names do not match bean property names, this attribute can be used to specify which request parameter should be used to obtain the value for a specific bean property.
D. The value to assign to a bean property. The value typically is the result of a JSP expression.
Which statements are BEST describe id attribute of <jsp:useBean id=..... /> Action?
A. The name used to manipulate the Java object with actions <jsp:setProperty> and <jsp:getProperty>. A variable of this name is also declared for use in JSP scripting elements. The name specified here is case sensitive.
B. The scope in which the Java object is accessible—page, request, session or application. The default scope is page.
C. The fully qualified class name of the Java object.
D. The name of a bean that can be used with method instantiate of class java.beans.Beans to load a JavaBean into memory.
E. The type of the JavaBean. This can be the same type as the class attribute, a superclass of that type or an interface implemented by that type. The default value is the same as for attribute class. A ClassCastException occurs if the Java object is not of the type specified with attribute type.
Which statements are BEST describe errorPage attribute of <%@ page errorPage=....%> directive?
A. Any exceptions in the current page that are not caught are sent to the error page for processing. The error page implicit object exception references the original exception.
B. Specifies if the current page is an error page that will be invoked in response to an error on another page. If the attribute value is true, the implicit object exception is created and references the original exception that occurred.
C. Specifies the MIME type of the data in the response to the client. The default type is text/html.
D. Specifies the class from which the translated JSP will be inherited. This attribute must be a fully qualified package and class name.
Action _______has the ability to match request parameters to properties of the same name in a bean by specifying "*" for attribute property.
A. <jsp:setProperty>
B. <jsp:getProperty>
C. <jsp:useBean>
D. <jsp:include>
Which of the following are potentially legal lines of JSP source?
A. <jsp:useBean id="beanName1" class="a.b.MyBean" type="a.b.MyInterface" />
B. <% String className = "a.b.MyBean"; %>
<jsp:useBean id="beanName2" class="<%=className%>" />
C. <% String beanName = "beanName3"; %>
<jsp:useBean id="<%=beanName3%>" class="a.b.MyBean" />
D. <% String propName = "soleProp"; %>
<jsp:getProperty name="beanName1" property="<%=propName%>" />
What sub element of <attribute> tag defines the name of the attribute that might be passed to the tag handler? (Choose one)
A. <attribute-name>
B. <name>
C. <attributename>
D. <param-name>
What should be the value of <body-content> subelement of element <tag> in a TLD file if the tag should not have any contents as its body?
A. blank
B. empty
C. null
D. false
Identify the correct element is required for a valid <taglib> tag in web.xml (Choose one)
A. <uri>
B. <tag-uri>
C. <uri-name>
D. <uri-location>
E. <taglib-uri>
Which of these is legal return types of the doAfterBody method defined in a class that extends TagSupport class?.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_AGAIN
D. SKIP_BODY
E. SKIP_PAGE
Which of the following elements defines the properties of an attribute that a tag needs?
A. attribute
B. tag-attribute
C. tag-attribute-type
D. attribute-type
Which element defined within the taglib element of taglib descriptor file is required? Select one correct answer.
A. Tag
B. Description
C. Validator
D. Name
Which of the following is a properly formatted taglib element occurring in web.xml?
A. <taglib>
<uri>/graph</uri>
<location>/WEB-INF/Charts.tld</location>
</taglib>
B. <taglib>
<lib-uri>/graph</lib-uri>
<lib-location>/WEB-INF/Charts.tld</lib-location>
</taglib>
C. <taglib>
<taglib-name>/graph</taglib-name>
<taglib-location>/WEB-INF/Charts.tld</taglib-location>
</taglib>
D. <taglib>
<taglib-uri>/graph</taglib-uri>
<taglib-location>/WEB-INF/Charts.tld</taglib-location>
</taglib>
Study the statements:
1) URL rewriting may be used when a browser is disabled cookies.
2) In URL encoding the session id is included as part of the URL
Which is the correct option ?
A. Only statement 1 is true
B. Only statement 2 is true
C. Both 1 and 2 are true
D. Both 1 and 2 are not true
A JSP page will not have access to session implicit variable if.
A. the user has closed all his/her browser windows.
B. the request is the first request from the user.
C. the user's browser does not support URL rewriting.
D. the session attribute of page directive is set to false.
hich statements are BEST describe type attribute of <jsp:useBean type=_.. /> action?
A. The name used to manipulate the Java object with actions <jsp:setProperty> and <jsp:getProperty>. A variable of this name is also declared for use in JSP scripting elements. The name specified here is call..
B. The name of a bean that can be used with method instantiate of class java.beans.Beans to load a JavaBean into memory.
C. The fully qualified class name of the Java object
D. The type ofthe JavaBean. This can be the same type as the class attribute, a superclass ofthattype or an interface implemented bythattype. The default value is the same as for attribute class. ACIassCai
E. The scope in which the Java object is accessible-page. request session or application. The default scope is page.
HttpServletRequest.getSession() method returns a_____object.
A. HttpServletSession.
B. HttpResponseSession.
C. HttpRequestSession.
D. HttpSession.
Class HttpServlet defines the methods _____ and _______ to response to get and post request from a client.
A. DoGet, DoPost
B. doGet, doPost
C. doGET, doPOST
D. Get, Post
Which of the elements defined within the taglib element of taglib descriptor file are required? Select one correct answer.
A. taguri
B. info
C. taglib-location
D. display-name
Which of the following method calls can be used to retrieve an object from the session that was stored using the name "userid"?
A. getValue("userid");
B. get("userid");
C. getAttribute("userid");
D. getParameter("userid");
. E.getObject("userid");
Which Java technology provides a standard API for publish-subscribe messaging model?
A. JNDI
B. UDDI
C. JMS
D. JSP
Consider the Servlet definition in a web.xml file below.
(see picture)
What will the following line of code return if present in the init() method of TestServlet?
getlnitParameter(1);
A. It will return "US".
B. Compilation error.
C. It will return null.
D. It will return "eastern".
E. Runtime error.
Your web application logs a user in when she supplies username/password. At that time a session is created for the user. Your want to let the user to be logged in only for 20 minutes. The application should redirect the user to the login page upon any request after 20 minutes of activity. Which of the following HttpSession methods would be helpful to you for implementing this functionality?
A. getCreationTime()
B. getLastAccessedTime()
C. getMaxInactiveInterval()
D. getLastAccessTime()
A JavaBeans component has the following field.
private boolean enabled
Which pairs of method declarations follow the JavaBeans standard for accessing this field?
A. public boolean setEnabled( boolean enabled)
public boolean getEnabled()
B. public void setEnabled( boolean enabled)
public boolean getEnabled()
C. public Boolean setEnabled( boolean enabled)
public boolean isEnabled()
D. public void setEnabled( boolean enabled)
public void isEnabled()
A JSP page has the following page directives:
<%@page isErrorPage='false' %>
<%@page errorPage='/jsp/myerror.jsp' %>
Which of the following implicit object is NOT available to the jsp page?
A. session
B. response
C. application
D. exception
Which of the following task may happen in the translation phase of JSP page? (Choose one)
A. Instantiation of the servlet class.
B. Creation of the servlet class corresponding to the JSP file.
C. None of the others
D. Execution of JspServiceQ method.
A bean present in the page and identified as 'mybean' has a property named 'name'. Which of the following is a correct way to print the value of this property?
A. <%=jsp:getProperty name="mybean" property="name"%>
B. <%out.println(mybean.getName())%>
C. <jsp:getProperty name="mybean" property="name"/>
D. <%=out.println(mybean.getName())%>
_____ sends a request to an object and includes the result in a JSP file.
[A]
include directive
[B]
import directive
[C]
<jsp:forward>
[D]
<jsp:include>
A bean with a property color is loaded using the following statement
<jsp:useBean id="fruit"
Which statement may be used to set the color property of the bean.
A <jsp:setColor id="fruit" property= "color" value="white"/>
B <jsp:setColor name="fruit" property= "color" value="white"/>
C <jsp:setValue name="fruit" property= "color" value="white"/>
D <jsp:setProperty name="fruit" property= "color" value="white">
F <jsp:setProperty id="fruit" property= "color" value="white">
E <jsp:setProperty name="fruit" property= "color" value="white"/>
A bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
Which of the following statements may be used to print the value of color property of the bean. Select the one correct answer.
A. <jsp:getColor bean="fruit"/>
B. <jsp:getProperty id="fruit" property="color"/>
C. <jsp:getProperty bean="fruit" property="color"/>
D. <jsp:getProperty name="fruit" property="color"/>
E. <jsp:getProperty class="Fruit" property="color"/>
Which statements are BEST describe uri attribute of <%@ taglib uri=_%>directive of JSP file?
A. The scripting language used in the JSP. Currently, the only valid value for this attribute is java.
C. Specifies the relative or absolute URI of the tag library descriptor.
D. Specifies the required prefix that distinguishes custom tags from built-in tags. The prefix names jsp. jspx. java, javax. servlet sun and sunw are reserved.
B. Allows programmers to include their own new tags in the form of tag libraries. These libraries can be used to encapsulate functionality and simplify the coding of a JSP.
In which of the following cases will the method doEndTag() of a tag handler be invoked?
A. It will be invoked only if doStartTag() or doAfterBody() return Tag.DO_END_TAG
B. It will be invoked only if doStartTag() and doAfterBody() complete successfully
C. This method is invoked if doStartTag() method returns true
D. It will be invoked in all case even if doStartTag() or doAfterBody() throw an exception
In which of the following case will the method doStartTag() of a tag handler be invoked?
A, If doEndTag() returns EVAL TAG AGAIN
C .It will be invoked only If the use of that tag is not enclosed in another custom tag.
E. This method is always invoked whenever the tag's use is encountered in the jsp page.
D. This method is invoked if doTag() method returns DO START
B . This method is invoked if doTag() method returns true.
Which of the following is a properly formatted taglib element occurring in web.xml?
B. <taglib>
<lib-uri>/graph</lib-uri>
<lib-location>/WEB-INF/Charts.tld</lib-location>
</taglib>
C. <taglib>
<taglib-name>/graph</taglib-name>
<taglib-location>/WEB-INF/Charts.tld</taglib-location>
</taglib>
A. <taglib>
<uri>/graph</uri>
<location>/WEB-INF/Charts.tld</location>
</taglib>
D. <taglib>
<taglib-uri>/graph</taglib-uri>
<taglib-location>/WEB-INF/Charts.tld</taglib-location>
</taglib>
Your servlet may receive a request, which the servlet cannot handle. In such cases, you want to redirect the request to another resource which may or may not be a part of the same web application. Which of the following options can be used to achieve this objective?
A. RequestDispatcher rd = request.getRequestDispatcher("some url");
rd.forward(request, response);
B. response.sendRedirect("some url");
C. request.sendRedirect("some url");
D. RequestDispatcher rd = this.getServletContext().getRequestDispatcher("some url");
rd.forward(request, response);
Your jsp page uses java.util.TreeMap. Adding which of the following statement will ensure that this class is available to the page?
A. <%@ page import="java.util.TreeMap"%>
B. <%! import="java.util.TreeMap"%>
C. <%@ import="java.util.TreeMap"%>
D. <%! page import="java.util.TreeMap"%>
______includes a static file in a JSP file, parsing the file's JSP elements
A. <jsp:forward>
B. <jsp:useBean>
C. import directive
D. include directive
E. <jsp:include>
Consider the following taglibrary descriptor element:
<tag>
<name>Hello</name>
<tag-class>com.abc.HelloTag<tag-class>
<body-content>...</body content>
</tag>
Which of the following is NOT a valid value for <body-content> element?
A. generic
B. empty
C. JSP
Which of the following statement is correct?
A. Authentication means determining whether one has access to a particular resource or not.
B. Data Integrity means that the data cannot be viewed by anybody other than it's intended recepient.
C. Data Integrity means that the data is not modified in transit between the sender and the receiver.
Which of the given jsp statement is equivalent to: <%=userbean.getAge()%>. Assume that userbean.getAge() returns an integer.
A. <jsp:getProperty name="userbean" method="getAge"/>
B. <jsp:getProperty name="userbean" property="Age"/>
C. <jsp getProperty name="userbean" property="getAge"/>
D. <jsp:getProperty name="userbean" property="age"/>
You need to make sure that the response stream of your web application is secure. Which factor will you look at?
A. authorization
B. authentication
C. data integrity
