aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Attribute Listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Attribute Listener" Watch "Attribute Listener" New topic
Author

Attribute Listener

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Can some one please help me in running this program.
I dont know what to write in the Listener's class. I know I have to implement ServletRequestAttributeListener interface and implement the attributeAdded(ServletRequestAttributeEvent ev), attributeRemoved(ServletRequestAttributeEvent ev), attributeReplaced(ServletRequestAttributeEvent ev) but what do i write with in those methods.
And how exactly is it supposed to work... I mean , in what way does the servlet link to the listener.
I am getting pretty confused



The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3166
    
  47

ServletRequestAttributeListener is a Listener class, it's methods will be notified when an attribute is added, removed or replaced from the request scope.

Generally you are not required to implement this interface. But in some practical cases, when you feel that you need to do 'something' on these events, you can implement this interface and write your own business logic for each events.

Devaka.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It seems that you have made your servlet to be a listener. You should make a new class for your listener.

Then, you have to register this listener in your application. This is done in the deployment descriptor.


The container will register this listener, and notify it any time an attribute is added/removed/replaced in a request.


[My Blog]
All roads lead to JavaRanch
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Thanks alot Christophe!

I am trying it out but getting a The requested resource () is not available.Have gone throught the code specially the DD but still no luck in findng the error

My Servlet Code is :

My Listener code


My Deployment Descriptor


From what i could make out in the log file , I think there is someproblem loading the Listener class.
Can any one spot any errors I am making.

Thanks!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Everything seems fine here. Can you tell us which URL did you use to access your servlet ? And posting the content of the log may help too.
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
The URL I am using is :

http://localhost:8080/Listener/AttributeTest.do

Path of the Folders

...../Tomcat 5.5/webapps/Listener---->WEB-INF----->web.xml

WEB-INF ---------> class ----> com --->example ---> MyServletAttribute.class

example--------->MyServletAttributeListener.class


My log file :

Jun 19, 2009 9:36:53 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;c:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Attachmate\E!E2K\;C:\j2sdk1.4.2_07;C:\Program Files\Java\jdk1.5.0_15\bin; ;C:\Program Files\QuickTime\QTSystem\
Jun 19, 2009 9:36:53 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 19, 2009 9:36:53 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2000 ms
Jun 19, 2009 9:36:53 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 19, 2009 9:36:54 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jun 19, 2009 9:36:54 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 19, 2009 9:36:56 AM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Jun 19, 2009 9:36:56 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/Listener] startup failed due to previous errors
Jun 19, 2009 9:36:57 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 19, 2009 9:36:58 AM org.apache.jk.common.ChannelSocket init
INFO: Port busy 8009 java.net.BindException: Address already in use: JVM_Bind
Jun 19, 2009 9:36:58 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8010
Jun 19, 2009 9:36:58 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=1 time=0/78 config=null
Jun 19, 2009 9:36:58 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jun 19, 2009 9:36:58 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4813 ms
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Any one with any answers?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

WEB-INF ---------> class
should be
WEB-INF ---------> classes
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
I dont know how changing class to classes made any difference ,since I couldnt find it mentioned anywhere in the DD .Only the package com.example was mentioned

Anyway, I am not getting the error... but also not getting any out put. The page is completely Blank !

My log file , if it helps

Jun 24, 2009 11:36:58 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;c:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Attachmate\E!E2K\;C:\j2sdk1.4.2_07;C:\Program Files\Java\jdk1.5.0_15\bin; ;C:\Program Files\QuickTime\QTSystem\
Jun 24, 2009 11:36:59 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 24, 2009 11:36:59 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 3578 ms
Jun 24, 2009 11:37:00 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 24, 2009 11:37:00 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jun 24, 2009 11:37:00 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 24, 2009 11:37:01 AM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Jun 24, 2009 11:37:01 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/Listener] startup failed due to previous errors
Jun 24, 2009 11:37:02 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 24, 2009 11:37:03 AM org.apache.jk.common.ChannelSocket init
INFO: Port busy 8009 java.net.BindException: Address already in use: JVM_Bind
Jun 24, 2009 11:37:03 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8010
Jun 24, 2009 11:37:03 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=1 time=0/78 config=null
Jun 24, 2009 11:37:03 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jun 24, 2009 11:37:03 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3672 ms
Jun 24, 2009 11:37:30 AM org.apache.coyote.http11.Http11BaseProtocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
Jun 24, 2009 11:37:32 AM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
Jun 24, 2009 11:37:32 AM org.apache.coyote.http11.Http11BaseProtocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
Jun 24, 2009 11:37:32 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Failed shutdown of Apache Portable Runtime
Jun 24, 2009 11:37:37 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;c:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Attachmate\E!E2K\;C:\j2sdk1.4.2_07;C:\Program Files\Java\jdk1.5.0_15\bin; ;C:\Program Files\QuickTime\QTSystem\
Jun 24, 2009 11:37:37 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 24, 2009 11:37:37 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 797 ms
Jun 24, 2009 11:37:37 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 24, 2009 11:37:37 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jun 24, 2009 11:37:37 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 24, 2009 11:37:38 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 24, 2009 11:37:39 AM org.apache.jk.common.ChannelSocket init
INFO: Port busy 8009 java.net.BindException: Address already in use: JVM_Bind
Jun 24, 2009 11:37:39 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8010
Jun 24, 2009 11:37:39 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=1 time=0/63 config=null
Jun 24, 2009 11:37:39 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jun 24, 2009 11:37:39 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1703 ms
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I dont know how changing class to classes made any difference

Class files of a web application must reside under WEB-INF/classes, not WEB-INF/class. Rename your directory.
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Thanks!!
I wasnt aware of that.

I did rename my directory and even thought i am not getting any error , i am also not getting any out put.
Getting a blank page
Mateus Lucio
Ranch Hand

Joined: Jul 27, 2006
Posts: 57
Hi there!!
take a look at this part of the exception

specially this line

INFO: Port busy 8009 java.net.BindException: Address already in use: JVM_Bind


Jun 24, 2009 11:37:37 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 24, 2009 11:37:37 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 797 ms
Jun 24, 2009 11:37:37 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 24, 2009 11:37:37 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jun 24, 2009 11:37:37 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 24, 2009 11:37:38 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 24, 2009 11:37:39 AM org.apache.jk.common.ChannelSocket init
INFO: Port busy 8009 java.net.BindException: Address already in use: JVM_Bind
Jun 24, 2009 11:37:39 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8010
Jun 24, 2009 11:37:39 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=1 time=0/63 config=null
Jun 24, 2009 11:37:39 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jun 24, 2009 11:37:39 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1703 ms



Port 8009 is in use by another application, this happens pretty often with me specially with the (damn) port 8080.

Just kill the process that's using this port. it's usually gtalk or msn, if your running on Windows OS, search for a software named "active ports" it shows all the used ports and the application that's using it.


Studying ...
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Mateus Lucio wrote:

Port 8009 is in use by another application, this happens pretty often with me specially with the (damn) port 8080.

Just kill the process that's using this port. it's usually gtalk or msn, if your running on Windows OS, search for a software named "active ports" it shows all the used ports and the application that's using it.



Thanks Mateus!
I did what you suggested. Downloaded the software and killed the program using port 8009 coz that was the only way to know what programs were using 8009. Happened to be a "ventC.exe"
But I still did not get any output, just getting a blank page.

Thanks for mentioning the port problem.. I had no idea problems like this could exist too.. was so wrapped up in coding and mapping!! Phewww!
In case my log makes any more sense to you or anyone else ....


INFO: Server startup in 6063 ms
Jun 25, 2009 5:43:51 PM org.apache.coyote.http11.Http11BaseProtocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
Jun 25, 2009 5:43:52 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
Jun 25, 2009 5:43:53 PM org.apache.coyote.http11.Http11BaseProtocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
Jun 25, 2009 5:43:53 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Failed shutdown of Apache Portable Runtime
Jun 25, 2009 5:44:04 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;c:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Attachmate\E!E2K\;C:\j2sdk1.4.2_07;C:\Program Files\Java\jdk1.5.0_15\bin; ;C:\Program Files\QuickTime\QTSystem\
Jun 25, 2009 5:44:05 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 25, 2009 5:44:05 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 750 ms
Jun 25, 2009 5:44:05 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 25, 2009 5:44:05 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jun 25, 2009 5:44:05 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 25, 2009 5:44:06 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 25, 2009 5:44:06 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jun 25, 2009 5:44:06 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/78 config=null
Jun 25, 2009 5:44:06 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jun 25, 2009 5:44:06 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1516 ms
Jun 25, 2009 5:44:16 PM org.apache.coyote.http11.Http11BaseProtocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
Jun 25, 2009 5:44:17 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
Jun 25, 2009 5:44:17 PM org.apache.coyote.http11.Http11BaseProtocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
Jun 25, 2009 5:44:17 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Failed shutdown of Apache Portable Runtime
Jun 25, 2009 5:44:25 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;c:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Attachmate\E!E2K\;C:\j2sdk1.4.2_07;C:\Program Files\Java\jdk1.5.0_15\bin; ;C:\Program Files\QuickTime\QTSystem\
Jun 25, 2009 5:44:25 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 25, 2009 5:44:25 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 782 ms
Jun 25, 2009 5:44:25 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 25, 2009 5:44:25 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jun 25, 2009 5:44:25 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 25, 2009 5:44:26 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 25, 2009 5:44:26 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jun 25, 2009 5:44:26 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/78 config=null
Jun 25, 2009 5:44:26 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jun 25, 2009 5:44:26 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1531 ms
Mateus Lucio
Ranch Hand

Joined: Jul 27, 2006
Posts: 57
Hi again!!

Try to switch your

System.out.println("message")

to
ev.getServletContext().log("message");


"ev" is the ServletRequestAttributeEvent passed to the listeners methods.
Tomcat by default is not configured to use the standard output (stdout) so it doesn't know what to do with a System.out.println.

If you just replace the code like I suggested you will use the default log mechanism which is not really used in a development/production environment because it's too simple, but works perfectly for studing purposes.

if you really want to enable System.out.println you will have to do a little search, because I don't remember how to do that, sorry .... I know it's possible because I did it once on JBoss.

Sorry for the incomplete answer ... when I saw my old friend "JVM Bind Exception" I just tought "Who's using that port again !!!???".
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Tomcat by default is not configured to use the standard output (stdout) so it doesn't know what to do with a System.out.println.

I've always used System.out.println with Tomcat without changing anything, and everything is logged in stdout_YYYYMMDD.log.
Mateus Lucio
Ranch Hand

Joined: Jul 27, 2006
Posts: 57
Hi Christophe!

That's really weird, my tomcat is behaving exactly like Nabila's, with System.out.println nothing is added to the log file.

Do you have a log4j.properties in tomcat/lib folder I think thats where you configure appenders for tomcat. I know you said you did not make any change in tomcat, would you mind take a look at that folder please?
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Okay .. I am really not getting what's the problem with my code or with Tomcat or whatever...
If I cant get these simple code to run what am I gona do when I get to the tougher parts ! t

I tried replacing the System.out.println with ev.getServletContext().log("...") but even that didn't work.
I am guessing, in this case the out put was to be seen in the log and not on the web page.Either way it didnt work out.
But thanks for the Suggestion !


Christophe.. Can you please help us out here ?
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Christophe Verré wrote: Class files of a web application must reside under WEB-INF/classes, not WEB-INF/class. Rename your directory.


But in Netbeans web.xml in in the WEB-INF folder and JSPs are in Web pages folder. Servlets and other java classes are in the <default package> under Source Packages.
Mateus Lucio
Ranch Hand

Joined: Jul 27, 2006
Posts: 57
@Harshana
When you use an IDE sometimes things can get out of place, the IDE makes sure everything is correctly packaged when you deploy your application.
Compiled class files (files with .class extension) must be under WEB-INF/classes, source class files (files with .java extension) can be anywhere you like.

@Nabila
Calm down, something things just get stuck!

Try something different this time ... I presume you are using a Windows OS, so try this:
Open CMD (also known as command console, command prompt, DOS console or DOS prompt).
Access your tomcat folder using it (type cd c:\tomcatfolder\bin)
Type startup (just it, without any extension) and hit enter.

Another console window will be opened showing tomcat's log
now run your test (use System.out.println in your listener)
This console window will be your stdout and you will see your messages printed. Your log file will still not show those messages, since this way your stdout is on the screen. To shut tomcat down type CTRL+C

if you don't mind, create a file named "log4j.properties" inside tomcatfolder/lib and paste this lines inside it:


Save and restart tomcat.

This time you should see your System.out.println on the screen and your ServletContext.log in the log file.



Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Mateus Lucio wrote:
Type startup (just it, without any extension) and hit enter.




I get an error while typing "startup" - "startup is not recognisable as an internal or external command,operable program or batch file."
This is probably because I installed Tomcat using Window Service Installer.
So i dont have a a startup.bat file in the folder.
Mateus Lucio
Ranch Hand

Joined: Jul 27, 2006
Posts: 57
Well, I don't like using tomcat as a service, it's harder to debug this way.

Anyway, add the "log4j.properties" to your tomcat/lib folder. I Believe that will solve your problem
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Mateus Lucio wrote:Do you have a log4j.properties in tomcat/lib folder I think thats where you configure appenders for tomcat. I know you said you did not make any change in tomcat, would you mind take a look at that folder please?

No, nothing there. First thing, I'm not using log4j. I'm sticking to java.util.logging (or more exactly to JULI). I've never configured Tomcat and all my System.out messages go to the stdout. Check this url.

The default logging.properties specifies a ConsoleHandler for routing logging to stdout and also a FileHandler.


Nabila, things are not going the way they should be. I think you should forget about log4j for the moment (sorry Mateus, I think we should leave this issue for the moment). Can you shutdown Tomcat, remove all log files from the "logs" folder, restart Tomcat, and access your servlet again ? Add a System.out.println into the doGet method of your servlet, and recompile it. (make sure the .class file is under the WEB-INF/classes/com/example) Restart Tomcat.

Then check the file called stdout_yyyymmdd.log under the "logs" directory. Can you copy/paste its content here ?
Katrin Perry
Ranch Hand

Joined: Mar 07, 2007
Posts: 61
Hi,

I just tried your code and it works fine. I could see the ouptut in /logs/stdout_20090628.log

Make sure you pick up the correct log file. Because of the way Windows Vista orders file in WindowsExplorer I was first picking up the wrong file. This might not be the reason why you can't find your output, but just in case. It is worth checking.

Thanks
Katrin


Katrin
SCJP 5.0, SCWCD, SCBCD, Oracle Certified Master Enterprise Architect
Mateus Lucio
Ranch Hand

Joined: Jul 27, 2006
Posts: 57
Hi Christophe !!
Please, there is no need to apologize, let's wait for Nabila's response, I hope it works with your suggestion.

I read the info in tomcat's user guide and you are right, System.out.println should work
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Firstly , Thanks for all your help (And sorry for the delay in my response)


I did do all what Christophe asked me to do.
I AM getting the out put in the stdout file. (Phewww)
I guess I had been getting the output all the time in the stdout file, Only I was looking for the it in the Catalina file.
(Katrin , Thanks for pointing that out - I really appreciate it !)

But I was wondering, is this how its supposed to be?
I was expecting it to the out put to be in the browser...


Christophe , Mateus - Thanks for bearing with me and taking the time to help me out!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It's good to hear everything went fine at last.

But I was wondering, is this how its supposed to be?
I was expecting it to the out put to be in the browser...

Yes, this is how it is supposed to be. The output of the client is managed by another stream, which you can access via methods like ServletResponse's getOutputStream() or getWriter();
Mateus Lucio
Ranch Hand

Joined: Jul 27, 2006
Posts: 57
Christophe Verré wrote:
It's good to hear everything went fine at last.


Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Attribute Listener