• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP, JDBC servlet + incomplete HTML

 
J.Schlanger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy
Not completely sure if this should be in the servlet forum or the JSP forum but here goes...
I am using a JSP page that includes a database query servlet (the servlet retrieves parameters via the session object). The servlet is invoked fine and returns content to the JSP.
However, the HTML code below the servlet call in the JSP page is only output when there is no tidy up code in the servlet i.e when I do not specifically close the Statement object or the ResultSet object.
When I close one of these objects there is no HTML below the servlet call.
I was told by someone that a PrintWriter object lasts for the duration of the JSP request. I do not understand why closing the above objects would close/affect the PrintWriter object? I am assuming this is what is happening as there is no further output/processing of the JSP page below the servlet call.
The code I have works but it would be great to really understand what is going on behind the scenes. I am a relative newbie programmer and was taught that you should always tidy up hence I think the working code I have in the servlet is currently...incomplete.
Any ideas/pointers would be greatly appreciated.
Many thanks.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you passing back to the JSP Page? If you are passing the ResultSet, that would explain a lot! The ResultSet object wraps a stream back to the database, you close that stream by closing either the Statement or Connection, NO ResultSet!
You are better readding the ResultSet in the Servlet into an Object Array and setting that Array on the Request for the JSP Page to use.
 
J.Schlanger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks, this has sorted it out a treat!
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey General,
JavaRanch has a Naming Policy Obviously fictitious names are not permitted. Please change your display name to follow the policy.
Thanks and looking forward to seeing you more 'round these parts.
 
J.Schlanger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, got yah (former General...now stripped of title!).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!