You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nikola Milutinovic <Ni...@ev.co.yu> on 2001/12/17 09:30:58 UTC

What's the word on a Servlet/JSP including itself in recursion?

Hi all.

Never got a response on this one.

Suppose I have a JSP page or a Servlet that includes ITSELF in recursion. I'm doing this because I have a n-tree structure and I wish to display a given node with all it's subnodes. I need recusrion. Period.

So I thought that something like this would do the trick:

<%
if( !partial ) {
%>
<html>
...
<%
}

while( resultSet.next() ) {
  int id=resultSet.getInt( "id" );
%>
<jsp:include page="<%= \"orgUnitDisplay.jsp?partial=true&id=\" + id %>" />
...
<%
} //while
if( !partial ) {
%>
...
</html>
<%
}
%>

PROBLEM
------------

Problem is I'm getting constant unexplicable errors. For a while, the JSP would descend one level into the sub-tree and then just end all output on response. I mean, the HTML code was left unfinished, not even the HTML table was completed. Like the response was cut in the middle.

Now I'm getting JDBC error "NullPointerException" in "next()". The funny part is, I've tried placing a "breakpoint" in the form of:

if( true ) throw new ServletException( "CHECKPOINT" );

in all lines in the JSP page. Wherever I place it, the JSP page runs into it, but not into "NullPointerException". If I comment it out, I get the NullPointer. So, it looks to me like things get screwed up AFTER JSP returns from a recursion. The JSP page regularely creates a statement, gets a result set and closes these, respectively before exiting.

QUESTION
-------------

Any idea? I thought that when a servlet (or a JSP page) calls another one or itslef, Servlet engine should create a new instance of the Servlet to handle the request. My problem might indicate otherwise, which is strange...

Nix.

Re: What's the word on a Servlet/JSP including itself in recursion?

Posted by Mahesh Vaidya <fo...@yahoo.com>.
IMHO Donot do that way.
Keep a single Jsp/Servlet. Rather encapsulate "tree" in
any suitable Java Collection. (viz. java.util.Tree)
Use iterator interface and accomplish whatever you want to
-Mahesh.
-------------------------------------------------------------------
Nikola Milutinovic wrote:

>Hi all.
>
>Never got a response on this one.
>
>Suppose I have a JSP page or a Servlet that includes ITSELF in recursion. I'm doing this because I have a n-tree structure and I wish to display a given node with all it's subnodes. I need recusrion. Period.
>
>So I thought that something like this would do the trick:
>
><%
>if( !partial ) {
>%>
><html>
>...
><%
>}
>
>while( resultSet.next() ) {
>  int id=resultSet.getInt( "id" );
>%>
><jsp:include page="<%= \"orgUnitDisplay.jsp?partial=true&id=\" + id %>" />
>...
><%
>} //while
>if( !partial ) {
>%>
>...
></html>
><%
>}
>%>
>
>PROBLEM
>------------
>
>Problem is I'm getting constant unexplicable errors. For a while, the JSP would descend one level into the sub-tree and then just end all output on response. I mean, the HTML code was left unfinished, not even the HTML table was completed. Like the response was cut in the middle.
>
>Now I'm getting JDBC error "NullPointerException" in "next()". The funny part is, I've tried placing a "breakpoint" in the form of:
>
>if( true ) throw new ServletException( "CHECKPOINT" );
>
>in all lines in the JSP page. Wherever I place it, the JSP page runs into it, but not into "NullPointerException". If I comment it out, I get the NullPointer. So, it looks to me like things get screwed up AFTER JSP returns from a recursion. The JSP page regularely creates a statement, gets a result set and closes these, respectively before exiting.
>
>QUESTION
>-------------
>
>Any idea? I thought that when a servlet (or a JSP page) calls another one or itslef, Servlet engine should create a new instance of the Servlet to handle the request. My problem might indicate otherwise, which is strange...
>
>Nix.
>



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>