Web Component Developer Exam:Servlets 2.3, JSP 1.2.


Why?

I am very grateful to www.javaranch.com. Thanks to this page I spotted lots of weak points when preparing the Programmers exam. It is also helping me now preparing for the Web Component Developer's Exam(the mock exam and the guys' notes:Ken,Miftah...,thanks to all), but there are not many tests to practise so I decided that maybe I could help in this area by creating my own test.You will tell me whether It helps or not. Thanks.

Note:the questions can't be those from the real exam as I am doing this while I am preparing for the exam(It will be 9th Nov 2001).

Also sorry for the english.It is my second laguage.

Last Update: 9 November 2001

Created by Eduardo Cobian (educobian@terra.es). This is my mock Exam based on the Objectives for the Sun Web Component Developer´s exam (more or less :-).

It comes with answers

I have tried to explain those topics that are more difficult to grasp (as far as my knowledge gets).

How does this compare to the real thing?

I haven't taken the exam yet, but this test should be more difficult than the real one.It is intended to spot weak areas so you know where you have to make more study. I have chosen those kind of questions that have given me a lot of trouble. So don't get upset if you don´t score high. If you find this test usefull please let me know. If you have critics also let me know.

Last minute update: Today I have passed the exam with 94% score(same as the programmers exam).2 or 3 questions are almost equal to the exam but I assure that all the questions have been done before taking the exam. My experience: Core Servlets and JSP (not updated but not bad). The notes on javarach.com but then I study very carefully the specifications.I have also read Advanced JavaServer Pages (only 90 total on jsp the rest is almos magic: front controller, session facade,how to create components,container and flowlayout of awt with jsp,... and a deep ,though not updated , explanation on custom tags ).I studied 3 weeks for the programmers and another 3 weeks for this test (12 hours a day). This test for me has been more or less as difficult as the programmers, only that I got 4 questions on patters I answer 3 of the just with Ken's note but the forth one was about Front controller that I could answer thanks to advanced javaserver pages.



Question 1)

Given the following to JSP files select the right answers.

<!-- file container.jsp -->

<html><body>
<%@ include file=”included.jsp” %>
<%@ page errorPage=”OneErrorPage.jsp” %>
</body></htm>

////////// different file
<!-- file included.jsp  -->
<html><body>
<%@ page errorPage=”AnotherErrorPage.jsp” %>
<i>Hello</i>
</body></html>

1) File container.jsp will compile if the directive page comes before the directive include
2) File container will compile and when executed it will show:”Hello”.
3) File container.jsp will compile if the errorPage in container.jsp is the same as in file included.jsp.
4) File container.jsp will compile if instead of directive  include  (<%@ include ...%>) it is used the action include      (<jsp:include...>) 

Answer to Question 1


Question 2)

What are correct statements about creating scripting variables for a Tag::

1) It is necessary to implement TagExtraInfo interface.
2) You have to insert into the tag element of the taglib descriptor file an entry for tei-class element.
3) The interface you have to implement has a method called getVariableInfo.
4) None of the previous.

Answer to Question 2


Question 3)

Which of the following staments are correct about the following jsp lines:

<jps:useBean id=”name” class=”java.lang.String” />

<%= name %>

1) It won't compile.
2) It is a valid jsp line and it will print the variable called name.
3) It will compile but it will always produce null as the output.
4) It will work if you create a javabean class with only one variable of type java.lang.String.

Answer to Question 3


Question 4)

Given the following jsp line select the correct statements:
<% public void jspInit() { ...java code...} %>

1) It is a valid line that can be used to initialize the servlet that implements the jsp file.
2) It won't compile as no identifer can start with jsp not _jsp.
3) It will serve as the servlet initialization if the function's name is _jspInit.
4) There is no way to initialize a jsp's implementation class servlet.

Answer to Question 4


Question 5)

What will be printed out if this jsp code?

<%! java.util.Locale class1=request.getLocale(); %>

<%= class %>

1) It won't compile.
2) It will print the default client's Web browser locale.
3) It will print the default web server Locale.
4) It will the first language specified in the Accept-Language request's header.

Answer to Question 5


Question 6)

What will be printed out if this jsp code?

<% java.util.Locale class =request.getLocale() %>

<%= s %>

1) It won't compile.
2) It will print the default client's Web browser locale.
3) It will print the default web server Locale.
4) It won't print the default Locale but the first language specified in the Accept-Language request's header.

Answer to Question 6


Question 7)

What is the return type of the getLastModified method of HttpServlet?

1) java.util.Date
2) java.sql.Date.
3) int.
4) long

Answer to Question 7


Question 8)

Which of the following are mandatory elements of the tagLibrary descriptor file?
1) tlib-version
2) jsp-version
3) short-name
4) tag

Answer to Question 8


Question 9)

What will be the result of running the following jsp file taking into account that the Web server has just been started and this is the first page loaded by the server?

<html><body>

<%= request.getSession(false).getId() %>

</body></html>


1)It won't compile

2)It will print the session id.

3)It will produce a NullPointerException as the getSession(false) method's call returns null, cause no session had been created.

4)It will produce an empty page.


Answer to Question 9


Question 10)


What statements are correct about the method PageContext.findAttribute(String name)?

1) There is no such method.
2) It searches the attribute in all 4 scopes.
3) It searches the attribute in page scope.
4) The method is findAttribute(String name, int scope)
 

Answer to Question 10


Question 11)

What are the methods of HttpSessionAttributeEvent?

1) There is no such event
2) getSession()
3) getName()
4) getValue() 

Answer to Question 11


Question 12)

Which are mandatory elements of the web-resouce-collection element?

1) web-resource-name
2) url-pattern
3) http-method
4) auth-constraint 

Answer to Question 12


Question 13)

Inside the body ( <elemnent>body</element>) of which elements can you use the element jsp:param?

1) <jsp:include ...>
2) <jsp:forward ...>
3) <jsp:params >
4) <servlet-params...>

Answer to Question 13


Question 14)

What are the types returned by the ServletContext method getResource and getResourceAsStream?

1) ServletContext doesn't have one of these two methods.
2) String and InputStream
3) URL and InputStream
4) URL and StreamReader

Answer to Question 14


Question 15)

Which of the following statements regarding HttpRequest methods are correct?

1) getHeaderNames returns an Enumeration
2) getHeaders returns a String[]
3) getHeaderValues returns a String[]
4) getIntParameter returns an int
 

Answer to Question 15


Question 16)

Which of the following is the formal parameter's type that the HttpRequest.setDateHeader( ? ) method accepts?

1) java.util.Date
2) java.sql.Date
3) int
4) none of the above

Answer to Question 16


Question 17)

Which statements are correct about the method PageContext.include?

1) There is no such method.
2) It has two paramters: request and response
3) It has one parameter of type String which is the relative URL of the page to include.
4) This method is appropiate to use within a Tag class.

Answer to Question 17


Question 18)

Which of the following statements PageConext methods pushBody and popBody are true?

1) pushBody is called by the jsp container after doStartTag and before doAfterBdy
2) pushBody is called by the jsp container before doInitBody
3) popBody is called by the jsp container after doAfterBody and before doEndTag
4) popBody is called by the jsp container after doEndTag


Answer to Question 18


Question 19)

Is it true that all tags have a parent tag,which is null for top-level tags, and is the innermost containing tag for nested tags.

1) yes
2) no
3) only the second part of the statement is true.

Answer to Question 19


Question 20)


What statements are correct about the method BodyTagSupport.doInitBody.

1) It is a method used by the jsp container and the jsp programmer shouldn't override it
2) It can be overriden if needed.
3) It can return either SKIP_BODY or EVAL_BODY_INCLUDE.
4) Its return type is void.

Answer to Question 20


Question 21)

Is correct the following program tag handler program?
public class MyTagHandler extends TagSupport {
  public int doStartTag() throws JspException {
    setValue(“name”, “value”);
    return EVAL_BODY_INCLUDE;
  }
}

1) yes
2) no

Answer to Question 21


Question 22)

1)In which cases is correct(and mandatory) to specify the extension .class?

1) findAncestorWithClass(this, MyTagHandler.class )
2) <jsp:useBean id=”myBean” class=”MyBean.class” />
3) <jsp:plugin type=”applet” code=”MyApplet.class” ...>
4) <tag-class>/tags/MyTagHandler.class</tag-class>


Answer to Question 22


Question 23)


Which of the following jsp action allow to specify the value of the attribute as an expresion(so it is evaluated at runtime)?

1) Attribute value of <jsp:setProperty name=”name” value=<%= expression %>
2) Attribute page of <jsp:include page=<%= expresion %>
3) Attribute value of <jsp:paran name=”name” value=<%= expression %>
4) Attribute name of <jsp:getProperty name=<% expression %>



Answer to Question 23


Question 24)

Given a tag handler defined with <bodycontent>JSP</bodycontent> which implements TagSupport and ONLY overrides doAfterBody with the following lines:

public int doAfterBody() throws JspException {
  try { pageContext.getOut().print(“ how are you? ”);}catch(IOException e) {}
  return SKIP_BODY;
}

What will be the result of a jsp with the following part?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>

1) The jsp page will print: Hello 
2) The jsp page will print: Hello how are you?
3) The jsp page will print: how are you? Hello
4) The jsp won't print anything.
 

Answer to Question 24


Question 25)

Given the following tag handler defined with <bodycontent>JSP</bodycontent> 

public class body extends TagSupport {
  public int doStartTag() throws JspException{
    return EVAL_BODY_INCLUDE;
  }
  public int doAfterBody() throws JspException {
    try {  pageContext.getOut().print("how are you?"); }catch(IOException e) {}
    return SKIP_BODY;
  }
}

what will be printed out by the following part of a jsp page?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>

1) The tag handler won't compile.
2) The jsp page will print Hello how are you?
3) The jsp page will print how are you? Hello
4) The jsp page will print Hello 

Answer to Question 25


Question 26)

Given the following tag handler defined with <bodycontent>JSP</bodycontent> 

public class body extends BodyTagSupport {
  public int doAfterBody() throws JspException {
    try {  pageContext.getOut().print("how are you?"); }catch(IOException e) {}
    return SKIP_BODY;
  }
}

what will be printed out by the following part of a jsp page?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>

1) The tag handler won't compile.
2) The jsp page will print Hello how are you?
3) The jsp page will print how are you? Hello
4) The jsp page will print Hello 

Answer to Question 26


Question 27)

1What will be the result of the following jsp action?
<jsp:setProperty name=”myBean” property=”factor” parameter=”inputFactor” />

1) The program won't compile
2) The servlet container will call myBean.setFactor() method with the content of the parameter inputFactor
3) The servlet container will call myBean.setInputFactor method with the content of the factor input
4) It will only work if the form parameter inputFactor is not empty when the form is submitted. 

Answer  to Question 27


Question 28)

1)Given the following web application deployment descriptor:
<web-app>
  <servlet>
    <servlet-name>myServlet</servlet-name>
    <servlet-class>MyServlet</servlet-class>
    ...
  </servlet>
  <servlet-mapping>
    <servlet-name>myServlet</servlet-name>
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>

which statements are true?

1) servlet-mapping element should be inside servlet element
2) url-pattern can't be defined that way.
3) if you make the http call: http://host/Hello.jsp the servlet container will execute MyServlet.
4) It would work with any extension excepting jsp,html,htm

Answer to Question 28


Question 29)

Which statements are correct regarding the following jsp lines that use a tag library?

<%! Vectot vector =new java.util.Vector();%>
<% vector.addElement(“one”); vector.addElement(“two”); %>
<prefix:suffix attr='vector' />

1) A vector can't be assigned to a tag handler attribute
2) The program will compile and assign the vector's content to the attribute attr.
3) The program will assign the content of vector if assigment is: attr='<%= vector %>'
4) Microsoft is the worst software company in history.

Answer to Question 29


Question 30)

Which statements are true regardin the use of action jsp:useBean?

1) you can't specify both class and beanName attributes
2) you can specify both type and class attributes
3) you can specify both type and beanName attritbutes
4) type attribute is used to specify a superclass of the javabean

Answer to Question 30 

Question 31)

Which statements are correct about the way a servlet can acces its initialization parameters?

1) By simply calling getInitParameter from any of the servlets methods (for example doGet)
2) It must be done by calling getServletConfig().getInitParaemter
3) It can only be done by overriding the method init(ServletConfig config)
4) It can be done by calling getServletContext().getInitParameter method 

Answer to Question 31


Question 32)

Which element should be used to give a canonical name to a jsp file( type the answer)?

1)Which element  should be used to give a canonical name to a jsp file( type the answer)?
<servlet> <servlet-name>aName</servlet-name> < ??? >jspFile.jsp</ ???>
(In case the question is not clear:what do you put instead of ??? ) 

Answer to Question 32


Question 33)

Which are methods of the HttpSessionActivationListener interface?


  1. sessionActivated

  2. sessionDeactivated

  3. sessionDidActivate

  4. sessionWillActivate



Answer to Question 33


Question 34)

Which statements are correct about listeners?

1) When shutting down the application they are called in order inversed of their appearance in the deployment descriptor.
2) They are registered in the deployment descriptor by the elements <listener> <session-listener>
3) A listener class can implement several listener interfaces
4) Jsp 1.2 introduced the tag handler listener.

Answer to Question 34


Question 35)

Which statements are correct about exceptions in servlets?

1) If there is defined an error page for an exception and a servlet included through a RequestDispathcer generates an exception,    the standar mechanism of calling that error page is not used, so the calling servlet can process the excpetion.
2) The element in the DD used to specify where the error page can be found is: <url-pattern>
3) If a servlet generates an exception not defined in a error page then the servlet container sets the response status 500
4) If a servlet generates a ServletException or subclass and no match is found in the error pages defined in the DD then, the servlet container tries again to find a match with the wrapped exception which is obtained by calling ServletException.getRootCause().

Answer to Question 35


Question 36)

Which statements are true about the method log?

1) log is a method GenericServlet class
2) log is a method of ServletContext interface
3) log is an overloaded method
4) There is a log method with the signature log(String, Exception)

Answer to Question 36


Question 37)

Which of the following statements about timeouts are correct?

1) In session-config element the timeout is specified in minutes
2) In cookies the maxAge is specified in seconds and a value of zero means cookie deletion
3) In sessions the maxInactiveInterval is specified with a long and a zero means a session with no timeout
4) If no session-config is specified and no maxInactiveInterval is spcecified the servlet container sets the default timeout.

Answer to Question 37


Question 38)

Which of the following are methods of the Cookie Class?


1) setComment
2) getVersion
3) setMaxAge
4) getSecure

Answer to Question 38


Question 39)

You are calling the method HttpServletResponse.sendRedirect(String path) and you want to make sure that the user continues in the same session. How do you that?

1) By calling the method with an absolute path as the argument
2) By enconding the path with HttpServletResponse.endcodeURL method
3) By enconding the path with HttpServletResponse.endcodeRedirectURL method
4) If you use sendRedirect the session is lost.

Answer to Question 39


Question 40)

Which statements are true about the auth-constraint element?

1) It only contains the element role-name (besides element description)
2) Only the role-name specified in security-role-ref can be used
3) It is a subelement of web-resource-collection
4) It is related to authentication


Answer to Question 40


Question 41)

Given the following declaration
<security-role-ref>
  <role-link>linkedRole</role-link>
  <role-name>roleName</role-name>
</security-role-ref>

Which method call is correct?

1) isUserInRole(linkedRole)
2) isUserInRole(roleName) 

Answer to Question 41


Question 42)

Which statements are correct about servlets implementing the SingleThreadedModel interfaces

1) Only one thread at a time will acces the service method
2) The servlet container may decide to create a pool of the servlet instances
3) The member variables are thread safe
4) none of the above

Answer to Question 42


Question 43)

Which jsp lines are correct?

1) <%! String myString=”Hello” %>
2) <% String myString=request.getServerName() %>
3) <%= out.print(“Hello”) %>
4) <%= “Hello” %>

Answer to Question 43


Question 44)

Which statements are correct?

1) HttpServlet.init() throws ServletException 
2) HttpServlet.service() thrwos ServletException and IOException
3) HttpServlet.destroy() throws ServletException 
4) HttpServlet.doHead() throws ServletException

Answer to Question 44


Question 45

Which statements are true about distributable web applications

1) There will be one instance of ServletContext in each VM
2) There will be only one instance of the default ServletContext in only one VM(the default ServletContext is one created for all servlets not deployed as part of an application are assigned) 
3) All request that are part of a session must be handled by one VM at a time
4) Container must notify any session attributes implementing the HttpSessionActivationListener interface during migration of a  session from one VM to another

Answer to Question 45


Question 46)

Which statements are correct?

1) Only ServletContext interface has method getRealPath
2) Answer 1 is incorrect because also HttpServletRequest has getRealPath method
3) Method getRealPath throws an IllegalArgumentException if it can't convert the argument to a local filesystem path
4) Method getPathInfo never returns null 

Answer to Question 46


Question 47)

Which statements are correct about character enconding methods? (Very difficult question for me)

1) ServletRequest has setCharacterEncoding method
2) ServletRequest has getCharacterEncoding method
3) ServletResponse has getCharacterEncoding method
4) ServletResponse has setCharacterEncoding method

Answer to Question 47


Question 48)

Which statements are correct about the HttpServletResponse's buffer

1) You can specify its size with the method setBufferSize with either a number ending with kb or the word none
2) If you use setBufferSize method after any content has been written the buffer won't be changed
3) reset will clear uncommited data including headers and status line
4) resetBuffer won't clear headers nor status line

Answer to Question 48


Question 49)

Which statements are correct about object implementing HttpSessionBindingListener interface?

1) valueBound method will be called before the object is accessible through getAttribute method
2) valueBound method will be called after the object is accessible through getAttribute method
3) valueUnbound method will be called before the object is removed from the session 
4) valueUnbound method will be called after the object is removed from the session 

Answer to Question 49 

Question 50)

Which statements are correct about security?

1) The security model doesn't apply when a servlet uses a RequestDispathcer to include or forward a resource
2) The security model doesn't apply when a servlet uses a RequestDispathcer to include a resource but it applies when it uses forward
3) The security model applies when a servlet uses a RequestDispathcer to include or forward a resource
4) The security model doesn't apply when a servlet uses a RequestDispathcer to include or include a static resource

Answer to Question 50


Question 51)

Which statements are true about the Web Application DD

1) There can't be leading nor trailing spaces for PCDATA whithin text nodes
2) The servlet container must ensure that role-names in auth-constraint are defined in security-role elemen
3) URI paths specified are assumed to be URL decoded form
4) None of the above

Answer to Question 51


Question 52)

Which are mandatory sub-elements of the web-app elements?

1) servlet element
2) login-config element
3) display-name element
4) There are no mandatory elements.

Answer to Question 52


Question 53)

Which statements are true about security-role-ref element

1) It is a sub-elements of web-app
2) It is a sub-elements of servlet
3) It is a sub-elements of security-role
4) It is a sub-element of auth-constraint

Answer to Question 53


Question 54)

Which statements are correct about load-on-startup elements

1) It must be an integer
2) It can be negative
3) If it is 0 (zero) it will be loaded at deployment time
4) Serveral servlets can have the same value for this element

Answer to Question 54


Question 55)

Which are mandatory sub-elements of login-config element

1) auth-method
2) realm-name
3) form-login-config
4) login-config doesn't have mandatory sub-elements

Answer to Question 55


Question 56)

How is it specified that an application is distributable

1) By specifying in the DD: <distributable>yes</distributable
2) By specifying in the DD: <distributable></distributable>
3) It is servlet container specific
4) An application can't be distributable

Answer to Question 56


Question 57)

What will be the result of this jsp line if the user takes a look at the page source code?
<!--  Today is <%= new java.util.Date() %>.Hava a nice day -->

1) It won't compile
2) The user won't see the comment
3) The user will see the same jsp line as above 
4) The user will see the comment with the current date because the expression is evaluated at runtime.

Answer to Question 57


Question 58)

Which statements are true about scope in jsp pages?

1) Objects with page scope are stored in the implicit object PageConttext
2) If a page forwards to another page, objects created with request scope in the source page will be visible in request of the forwarded  page
3) Objects with application scope can be created in pages that are not session-aware(with page attribute session=”false”)
4) The implicit page object has pageContext scope 

Answer to Question 58


Question 59)

Answer to Question 59

Which of the following are attributes of the page directive?

1) info
2) buffersize
3) pageEnconding
4) import

Question 60)

Attribute flush of jsp include action is a mandatory attribute

1) yes
2) no
3) Only the first time a jsp include action appears in a page



Answers


Answer 1)

Back to question 1)


4) File container.jsp will compile if instead of directive include (<%@ include ...%>) it is used the action include (<jsp:include ...>)

explanation:
With directive include (<%@ include file=”fileName” %>) the file is literaly included before compilation.In this case we have then, two lines with directive page both with attribute errorPage.That's an error. Then only attribute of directive page that can occur more than once is import.



Answer 2)

Back to question 2)

1)It is necessary to implement TagExtraInfo interface.
2)You have to insert into the tag element of the taglib descriptor file an entry for “tei-class” element.
3)The interface you have to implement (TagExtraInfo) has a method called getVariableInfo.

Answer 3)

back to Question 3)


2) It is a valid jsp line and it will print the variable called name.

It will work.To have valid functionality you have to set an attribute of String type in the proper scope before it is accessed by <jsp:useBean ...>


Answer 4)

Back to question 4)

1) It is a valid line that can be used to initialize the servlet that implements the jsp file.


Answer 5)

Back to question 5)

1)It won't compile.

The eight implicit objects in jsp pages are not visible in declarations.They are visible in scriplets and expressions.


Answer 6)

Back to question 6)
1) It won't compile.

You can define a variable with a reserved word.


Answer 7)

Back to Question 7)

4) long


Answer 8)

Back to Question 8)


1) tlib-version
2) jsp-version
3) short-name
4) tag

Answer 9)

Back to Question 9)

2)It will print the session id.

By default jsp pages are part of a session.That's why you have the implicit object session.You can turn off this default behaviour with the following line

<%@ page session=”false” %>.



Answer 10)

Back to question 10)

2) It searches the attribute in page,request,session,application scope in that order.


Answer 11)

Back to Question 11)

    1)There is no such event.

    There is the HttpSessionBindingEvent event.


Answer 12)

Back to Question 12)

1)web-resource-name

2) url-pattern


Answer 13)

Back to Question 13)
 
1)<jsp:include ...>
2) <jsp:forward ...>
3) <jsp:params >

Answer 14)

Back to Question 14)

3) URL and InputStream


Answer 15)

Back to Question 15)

1) getHeaderNames returns an Enumeration


Answer 16)

Back to Question 16)

none of the above.

It's long.


Answer 17)

3) It has one parameter of type String which is the relative URL of the page to include.
4) This method is appropiate to use it within a Tag class.

 Back to Question 17)



Answer 18)


    1)pushBody is called by the jsp container after doStartTag and before doAfterBdy
    3) popBody is called by the jsp container after doAfterBody and before doEndTag

Back to question 18)



Answer 19)

1) yes

Back to Question 19)



Answer 20)

2) It can be overriden.
4) Its return type is void.

Back to Question 20)



Answer 21)

Back to Question 21)
1) yes.

TagSupport has setValue(String,Object) and getValue(String) method to store information.


Answer 22)
Back to Question 22)

1) findAncestorWithClass(this, MyTagHandler.class )
3) <jsp:plugin type=”applet” code=”MyApplet.class” ...>

Answer 23)

Back to Question 23)
 
1) Attribute value of <jsp:setProperty name=”name” value=<%= expression %>
2) Attribute page of <jsp:include page=<%= expresion %>
3) Attribute value of <jsp:paran name=”name” value=<%= expression %>

Also attribute page of <jsp:forward ..>. I think that makes it all.

Answer 24)

4) The jsp won't print anything.

TagSupport.doStartTag by default returns SKIP_BODY and as it is not overriden the body is ignored.

Back to Question 24)



Answer 25)

4) The jsp page will print Hello 

As far as I know you can't print from doAfterBdoy in a TagSupport handlers.You could just repeat the evaluation of the body by returning EVAL_BODY_INCLUDE and stop the loop on some condition by returning SKIP_BODY.I couldn't test this last thing as I am using tomcat 3.2.3 which doesn't support jsp 1.2.

Back to Question 25
.


Answer 26)

Back to Question 26)

4) The jsp page will print Hello 

Inside doAfterBdoy the bodyContent is in a stack and the implicit variable out prints into the bodyContent not to the outputStream.The bodyContent keeps a reference to the buffered writer (either a enclosing bodyContent or the implicit out variable) called the previousOut.If you want to print inside doAFterBdoy you have to use this previousOut. To print things unrelated with the body use pageContext.getOut in doStartTag. By default doStartTag in BodyTagSupport returns EVAl_BODY_BUFFERED which produces a stack of bodycontents, one bodycontent for each iteration.If you don't want this stack to be create you have to override doStartTag and return EVAL_BODY_IHCLUDE, then the default out would print to the output stream (to the response).

Answer 27)

Back to Question 27)

1) The jsp program won't compile
It is param and not parameter that has to be specified in <jsp:setProperty name=”name” param=”param” /

Answer 28)

Back to Question 28

3) If you make the http call: http://host/Hello.jsp the servlet container will execute MyServlet.

Try it.


Answer 29)

Back to Question 29) 

3) The program will assign the content of vector if assigment is: attr='<%= vector %>'
4) Microsoft is the worst software company in history. Help to the end of it by not using its products.

Answer 30)

Back to Question 30

1) you can't specify both class and beanName attributes
2) you can specify both type and class attributes
3) you can specify both type and beanName atritbutes
4) type attribute is used to specify a superclass of the javabean

Answer 31)

Back to Question 31

    1)By simply calling getInitParameter from any of the servlets methods (for example doGet)

    It can also be done by calling getServletConfig().getInitParaemter, but it is not the only option.GenericServlet implements ServletConfig so it has all its methods.



Answer 32)

Back to Question 32)

<jsp-file>


Answer 33)

Back to Question 33)

3)sessionDidActivate

also sessionWillPassivate



Answer 34)

Back to Question 34)

1) When shutting down the application they are called in order inversed of their apperance in the deployment descriptor.
3) A listener class can implement several listener interfaces

Answer 35)

Back to Question 35
 
1) If there is defined an error page for an exception and a servlet included through a RequestDispathcer generates an exception,    the standar mechanism of calling that error page is not used, so the calling servlet can process the excpetion.
3) If a servlet generates an exception not defined in a error page then the servlet container sets the response status 500
4) If a servlet generates a ServletException or subclass and no match is found in the error pages defined in the DD then, the servlet container tries again to find a match with the wrapped exception which is obtained by calling ServletException.getRootCause().

Answer 36)

Back to Question 36
 
1) log is a method GenericServlet class
2) log is a method of ServletContext interface
3) log is an overloaded method

the log signatures are log(String) and log(String, Trhrowable)

Answer 37)

Back to Question 37
1) In session-config element the timeout is specified in minutes

1) In session-config element the timeout is specified in minutes
2) In cookies the maxAge is specified in seconds and a value of zero means cookie deletion
4) If no session-config is specified and no maxInactiveInterval is spcecified the servlet container sets the default timeout.t

Answer 38)

Back to Question 38)
 
1) setComment
2) getVersion
3) setMaxAge
4) getSecure

Answer 39)

Back to Question 39)
 
3) By enconding the path with HttpServletResponse.endcodeRedirectURL method

Answer 40)

Back to Question 40)
 
1) It only contains the element role-name

Answer 41)

Back to Question 41)
 
2) isUserInRole(roleName) 

Answer 42)

Back to Question 42

    4)none of the above.

    The name of the interface is SingleThreadModel not Threaded


Answer 43)

Back to Question 43)
 
4) <%= “Hello” %>

Answer 44)

Back to Question 44


1) HttpServlet.init() throws ServletException 
2) HttpServlet.service() thrwos ServletException and IOException
destroy throws nothing and all doXxx trhrows ServletException and IOException.

Answer 45)

Back to Question 45
 
1) There will be one instance of ServletContext in each VM
2) There will be only one instance of the default ServletContext in only one VM(the default ServletContext is one created for all servlets not deployed as part of an application are assigned) 
3) All request that are part of a session must be handled by one VM at a time
4) Container must notify any session attributes implementing the HttpSessionActivationListener interface during migration of a  session from one VM to another

Answer 46)

Back to Question 46
 
2) Answer 1 is incorrect because also HttpServletRequest has getRealPath method

Answer 47)

Back to Question 47
 
1) ServletRequest has setCharacterEncoding method
2) ServletRequest has getCharacterEncoding method
3) ServletResponse has getCharacterEncoding method

Answer 48)

Back to Question 48

3) reset will clear uncommited data including headers and status line
4) resetBuffer won't clear headers nor status line

If you call setBufferSize after data have been written it throws IllegalStateException.

Answer 49)

Back to Question 49)

1) valueBound method will be called before the object is accessible through getAttribute method
4) value Unbound method will be called after the object is removed from the sesion 

Answer 50)


Back to question 50

1) The security model doesn't apply when a servlet uses a RequestDispathcer to include or forward a resource

Answer 51)

Back to Question 51)

3) URI paths specified are assumed to be URL decoded form

Answer 52)

Back to Question 52)

4) There are no mandatory elements.

Answer 53)

Back to Question 53)

2) It is a sub-elements of servlet

Answer 54)

Back to Question 54)


1) It must be an integer
2) It can be negative
3) If it is 0 (zero) it will be loaded at deployment time
4) Serveral servlets can have the same value for this element

Answer 55)

Back to Question 55)

4) login-config doesn't have mandatory sub-elements

Answer 56)

Back to Question 56)

2) By specifying in the DD: <distributable></distributable>

It is an element with empty body.

Answer 57)

Back to Question 57)

4) The user will see the comment with the current date because the expression is evaluated at runtime.

This example is in the JSP especifications.

Answer 58)

Back to Question 58)

1) Object with page scope are stored in object PageConttext
If a page forwards to another page, objects created with request scope in the source page will be visible in request of the forwarded  page
3) Objects with application scope can be created in pages that are not session-aware(with page attribute session=”false”)

Answer 59)

Back to Question 59)

1) info
3) pageEnconding
4) import

Answer 60)

Back to Question 60)

2) no

End of document