Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Clarification on init() method of HttpServlet

 
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try that one..
Thanks!
 
Christian Dadulla
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sam !
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic