Consider the following code for the doGet() method:
public void doGet(HttpServletRequest req,
HttpServletResponse res)
{
PrintWriter out = res.getWriter);
out.println("<html><body>Hello</body></html>");
//1
if(req.getParameter("name") == null)
{
res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
Which of the following lines can be inserted at //1 so that the above code does
not throw any exception? (Select one)
a if ( ! res.isSent() )
b if ( ! res.isCommitted() )
c if ( ! res.isDone() )
d if ( ! res.isFlushed() )
e if ( ! res.flush() )
Answer: b
A web application is located in a directory named sales. Where should its
deployment descriptor be located? (Select one)
a sales
b sales/deployment
c sales/WEB
d sales/WEB-INF
e WEB-INF/sales
f WEB-INF
g WEB/sales
Answer: d
Consider the following class:
import javax.servlet.*;
public class MyListener implements ServletContextAttributeListener
{
public void attributeAdded(ServletContextAttributeEvent scab)
{
System.out.println("attribute added");
}
public void attributeRemoved(ServletContextAttributeEvent scab)
{
System.out.println("attribute removed");
}
}
Which of the following statements about the above class is correct? (Select one)
a This class will compile as is.
b This class will compile only if the attributeReplaced() method is added to it.
c This class will compile only if the attributeUpdated() method is added to it.
d This class will compile only if the attributeChanged() method is added to it.
Answer: b
Given these filter mapping declarations:
<filter-mapping>
<filter-name>FilterOne</filter-name>
<url-pattern>/admin/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>FilterTwo</filter-name>
<url-pattern>/users/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>FilterThree</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>FilterTwo</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
in what order are the filters invoked for the following browser request?
/admin/index.jsp
a FilterOne, FilterThree
b FilterOne, FilterTwo, FilterThree
c FilterThree, FilterTwo
d FilterThree, FilterTwo
e FilterThree
f None of these filters are invoked.
Answer: d
Which of the following methods will be invoked on a session attribute that
implements HttpSessionBindingListener when the session is invalidated?
(Select one)
a sessionDestroyed
b valueUnbound
c attributeRemoved
d sessionInvalidated
Answer: b
Which one of the following must be done before authorization takes place?
(Select one)
a Data validation
b User authentication
c Data encryption
d Data compression
Answer: b
Which of the following methods is defined by the JSP engine? (Select one)
a jspInit()
b _jspService()
c _jspService(ServletRequest, ServletResponse)
d _jspService(HttpServletRequest, HttpServletResponse)
e jspDestroy()
Answer: d