Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

include Vs jsp include  RSS feed

 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
kindly go thru the following code and reply the answer.it was asked in an interview.

case 1:

File i1.jsp:

<%! int i=10; %>

File i2.jsp:

<%@ include file="i1.jsp" %>
<%! i=10 %>

The o/p when i2.jsp is error due to redeclaration
---------------------------------------------------------------------------

case 2:

File i1.jsp:
<%! int i=10; %>

File i2.jsp:
<jsp:include page="i1.jsp" />
<%! int i=10 %>

No error when i2.jsp is called
----------------------------------------------------------------------------


regards
Raja
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you're asking why in the second case you don't get an error?
<%@ include file="..." %> inserts the contents of the file referenced into the current file, so you get two declarations in the same file.
<jsp:include page="..." /> inserts the contents of the file referenced *after it has been processed* into the output of the current file *while it is being processed*. So the declarations are in two different files, and thus don't clash.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
include is static, though jsp:include is on the fly. Hence compiler doesn't know about its redeclaration.

BTW, you missed to redeclare in your first case. You can make correction.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!