• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printing from class other than that which extends HttpServlet

 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a servlet sortof like this:



My question is how to I access variable 'out' of type PrintWriter in class ShouldWork from method print() in class TradeTreeNode? Obviously I'm trying to build up an unordered list on a page this servlet creates dynamically and ships back to the client.

TIA,

Still-learning Stuart
 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passed a reference to the PrintWriter object to the TradeTreeNodeList object in its constructor and saved it as an instance variable. This gives me a reference to a PrintWriter which goes to the servlet response.

CASE CLOSED

Still-learning Stuart
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not the best design.

It's generally not a good idea to pass container-managed objects around -- and especially to store them for alter reference.

Would it not be possible to simply have the non-servlet class return a text buffer that the servlet is responsible for writing to the output stream?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic