Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange output !! include / jsp:include

 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Say I have a JSP page - A.jsp which includes B.jsp (using include directive), B.jsp includes C.jsp (using include directive).
Now C.jsp instantiates a Bean and calls its method passing some variable as parameter, which returns a String, using below statements :
<jsp:useBean id="abean" class="com.some.plan.ABean" scope="request" />
<%
out.println( abean.getRequestedString(1) );
%>
The method in the bean is defined as follows :
public String getRequestedString(int code)
{
System.out.println("THIS METHOD CALLED ");
if (code==1)
return "1";
else
return "0";
}

I know that it should and is printing '1' in the browser. But let me come to the strange point now, on the server console , its printing 'THIS METHOD CALLED' two times !!! WHY ? which means the method is being called 2 times.
But if I put the below statement in A.jsp instead of C.jsp :
<%
out.println( abean.getRequestedString(1) );
%>
( since abean instance will also be available in A.jsp (after A.jsp includes C.jsp), putting the above statement in A.jsp is legal )
Now, after doing this change, on the browser it will print '1' and at the server console , 'THIS METHOD CALLED' is printed once, which according to me is right. But why if the above statement be put in C.jsp, the server console shows that the method is called two times.
Pls. someone let me know...
[ May 08, 2002: Message edited by: Sam Cala ]
 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HELLO !! WAKE UP
When including C.jsp in B.jsp by saying :
<%@ include file="C.jsp" %>
, after this statement I had a following JSP comment
<!-- <jsp:include page='calendar.jsp'/> -->
and I'm shocked, when I removed this comment from the coding, I see now at the server console, 'THIS METHOD CALLED' is printing just once. What this means ? Comments are also being processed ?
 
Ricardo Cortes
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam...I tried arduously to follow the details but got a little lost when you mentioning the line in A.jsp with the line from C.jsp. Can you simplify the example in anyway?
 
tony lee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i guess the code of C.jsp is inserted into B.jsp whose code is eventually added into A.jsp. System.out.println("THIS METHOD CALLED ") is executed for two times?
I'm confused here
 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
I'm using JRun 3.0, and its not nice to know that JRun internally processes the JSP comments also though does not give any output on the screen. Thats why the server console was printing the message two times as the one statement through which i was calling that bean was in JSP comment...
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have your comment coded wrong. You showed the following code being used in your JSP page:
<!-- <jsp:include page='calendar.jsp'/> -->
That is only an HTML comment. Here is how to use a JSP comment:
<%-- <jsp:include page='calendar.jsp'/> --%>
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic