• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat 6, exception and exact line of the bad .jsp

 
Ranch Hand
Posts: 40
Google Web Toolkit Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was wondering...

When an exception occurs, I get a nice stack trace to my log file, line number of the compiled servlet class, but I don't always get the exact line of my original jsp file. I usually do in case of some syntax or parsing errors of the .jsp file, but I see no dependency in case of runtime errors. Sometimes the .jsp line is there, sometimes not.

Is this configuration-dependent? I'd like to see that specific information every time, how can I achieve that?
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one of the biggest reasons why you should have little or no logic in JSPs.

In Tomcat - and you did ask in the Tomcat forum - the Jasper compiler converts the JSP into a servlet coded in Java. The Java equivalent of the JSP is written to the Tomcat work directory, where it is compiled into a java class. Displayed error line numbers are usually going to be based on the servlet's java source code, not on the original JSP.

In addition to the mere fact that you have to use indirection just to find the offending line number, reverse-engineering that line back to a JSP line number can be quite difficult, since aside from being obscured by housekeeping code, a certain amount of relocation takes place as well.

Moral of story: keep your Model and Controller code out of your View.
 
Maciej Drozdzowski
Ranch Hand
Posts: 40
Google Web Toolkit Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, sure, all you've said is pretty obvious.
but if you're lucky enough to come into an existing project with a lot of scriptlets in .jsp's, then the pleasure is all yours :P

my question is - how come that some exceptions, theoretically almost identical - like a NullPointerException - even from the same file - sometimes have .jsp's lines in the trace, and sometimes not. i usually encountered such exceptions in case of local variable declarations in .jsp's - null, exception, stack trace. sometimes full, sometimes not. and here's my confusion - i simply don't understand why that happens.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've had that pleasure.

Because of the way that tags are compiled and processed, they can generate code in remote parts of the output servlet. So their accounting of where their origins were can be a little fuzzy. Especially when one tag generates about 50 lines of Java code and puts it in 3 different places.

They probably could try harder to match them up, but it's never been worth the cost.
 
Maciej Drozdzowski
Ranch Hand
Posts: 40
Google Web Toolkit Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's a pity. nobody likes to see unpredictable behaviour which cannot be influenced.
damn you tomcat :P

thanks for your time!
 
Everybody! Do the Funky Monkey! Like this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic