• Post Reply Bookmark Topic Watch Topic
  • New Topic

no error shown while compiling java file but also no output

 
sahin sarkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI everyone,

I made a web app to test the ServletContextListener in tomcat according to the book head first servlets and jsps and used the code

out.println("test context attributes set by listener<br>");
Dog dog = (Dog) getServletContext().getAttribute("dog");
out.println("Dog's breed is: "+dog.getBreed());


in the listener class.
But the output is showing the first line only and the second println() is not showing any output whereas my Dog class compiled successfully and I didn't see any NullPointerException as expected in the book but somehow it seems like the problem is in the 2nd line of code only but I don't know what.
I also tried to add a 4th line at the end with println() only but with a simple text even that is not running but when I put that same line after the 1st line, the output is shown.
I am unable to see what has gone wrong in the 2nd line of code. Please help

Thanks in advance
 
sahin sarkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I got it. I had written the attribute name as "dog" in one place and "Dog" on the other place. Problem is resolved
 
S Majumder
Ranch Hand
Posts: 349
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Sachin ,
How to debug and where's the problem is also a good experience . Always try to see the log's generated by tomcat .Try to send the error to your UI (jsp) so that you can understand better and its a good practice .

Thanks ,
Satya
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!