• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clarification on init() method of HttpServlet

 
Christian Dadulla
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
When i try to override init() method in my servlet and wanted to print some String in the console using System.out.println("Some String");.. I didn't see the output in console.
Pls enlighten me on this one. Thanks!
 
Bhushan Jawle
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember someone else besides me mentioning this before. I think Tomcat has that problem with version 4 or 4.1 on Windows.
Try writing to a file to check whether servlet is actually initialized.
Thanks
 
Christian Dadulla
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try that one..
Thanks!
 
Christian Dadulla
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bhushan!
I tried writing to a file inside 'init()' method, and it does..
By the way the version of my Tomcat is
jakarta-tomcat-4.1.12 ..
Thanks !
 
jr gil
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also found that problem with the init(). I am using version 4.1.18. I finally used getServletContext() and the log() to write whatever I needed in the log. A bit of a pain to have to shut down Tomcat to look at the log but it told me what I needed to know at the time.
 
Bhushan Jawle
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better way would be use Log4j to log to a file that way you need not shut down server everytime.
Later you can reconfigure Lo4j to print to console
Thanks
 
Christian Dadulla
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again to the both of u !

Another thing..
Is there a method(or a way) to know how many active sessions(HttpSession) are there inside a servlet container?.. inside a web application?
Thanks in advance
 
Raji Ram
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have a class that implements HttpSessionListener interface.
Then you can increase the count when a new session is created in the sessionCreadted method and decrease the count in sessionDestroyed method.
If you have Manning book, Refer Pg no:121.
Good Luck!
 
Christian Dadulla
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
Yes, I have that book.. but i think that applies only for a certain web application..
How about tracking all active sessions inside a servlet container serving many web applications simultaneously?
Thanks again
 
Sam Dalton
Author
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may be able to do this using JMX (Java Management Extensions) Tomcat 4.1.x provides a JMX interface for management and monitoring.
Cheers
Sam
 
Christian Dadulla
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sam !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic