This week's book giveaway is in the Android forum.
We're giving away four copies of Android Programming: The Big Nerd Ranch Guide and have Bill Phillips & Chris Stewart on-line!
See this thread for details.
Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

printing from class other than that which extends HttpServlet  RSS feed

 
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
Posts: 65971
140
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
Boost this thread!