aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Clarification on init() method of HttpServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Clarification on init() method of HttpServlet" Watch "Clarification on init() method of HttpServlet" New topic
Author

Clarification on init() method of HttpServlet

Christian Dadulla
Greenhorn

Joined: Jan 08, 2003
Posts: 16
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!


SCJP2
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
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

Joined: Jan 08, 2003
Posts: 16
I will try that one..
Thanks!
Christian Dadulla
Greenhorn

Joined: Jan 08, 2003
Posts: 16
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

Joined: Jan 14, 2003
Posts: 7
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

Joined: Nov 22, 2001
Posts: 249
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

Joined: Jan 08, 2003
Posts: 16
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

Joined: Aug 22, 2002
Posts: 46
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!


Regards,<br />Raji.
Christian Dadulla
Greenhorn

Joined: Jan 08, 2003
Posts: 16
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

Joined: Jul 26, 2001
Posts: 170
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


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Christian Dadulla
Greenhorn

Joined: Jan 08, 2003
Posts: 16
Thanks Sam !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clarification on init() method of HttpServlet