• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

j2eecertficate.com question

 
cheenu Dev
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ques is:

Consider the following two JSP pages, which of the following elements can be inserted into basket.jsp so that 'deodorant baked beans nappies ' is displayed when basket.jsp is requested?

basket.jsp
<%
String[] basket={"deodorant", "baked beans", "nappies"};
pageContext.setAttribute("basket", basket, pageContext.REQUEST_SCOPE);
%>
<%-- Insert code here --%>

checkout.jsp
<% String[] basket = (String[])pageContext.getAttribute("basket",
pageContext.REQUEST_SCOPE);
for (int x=0; x < basket.length; x++) {
out.print(basket[x] + " ");
}
%>

1
<jsp:include page="checkout.jsp" />

2
<jsp:include file="checkout.jsp" />

3
<%@ include file="checkout.jsp" %>

4
<%@ include page="checkout.jsp" %>


the ans was 1 but how come 4 is not...
when a page is included statically cant it do the same???
 
Jan Kostelansky
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When page is included statically, content (not result) of page is inserted into enclosing page. In this case, compile error occurs, because of duplicity declaration of variable named
 
singh santosh
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
One more thing i would like to add to the above answer by jan.The Syntax of directive include is
<%@ include file="filename" /> but above instead of file its page .

regards
-santosh
 
cheenu Dev
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then if the string basket declaration line is removed from the included file u have to do static rather than dynamic right???
thanks...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic