Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jasper Exception

Status
Not open for further replies.

TiredOldDev

Programmer
Jul 14, 2005
4
CA
Ok, I get this error quite a bit.

It is not really helpful. In most cases a null reference is being used. However the error msg does not tell me WHERE the error occured. I can locate the working Tomcat .class and .java files for the JSP easily enough.

Is there a way to get Tomcat to report at least the line number in the generated .java file where the error occured?
 
Are you talking about a NullPointerException ?
Which logs have you checked ? In my 3 years of experience with varying versions of tomcat, I generally find a stack trace is printed somewhere !

Of course, the smart-arse answer would be that, like in C/C++, you should always check an object is not null before attempting to call a method on it ... but thats just me.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
More than just the NullPointerException, though i do not even get that. The code I use (in an all-encompassing try block):

Code:
catch (Exception fatal)
{
// if we are here, then something somewhere has seriously failed
StackTraceElement[] trace = fatal.getStackTrace();

for (int i = 0; i < trace.length; i++)
	Log.error( trace[i].getClassName() + "." + trace[i].getMethodName() + ":" + trace[i].getLineNumber() );

Which gives me
Code:
89,2005.07.14 12:17:23.812,org.apache.jasper.JasperException
91,2005.07.14 12:17:23.812,org.apache.jasper.servlet.JspServletWrapper.service:372
93,2005.07.14 12:17:23.812,org.apache.jasper.servlet.JspServlet.serviceJspFile:292
95,2005.07.14 12:17:23.812,org.apache.jasper.servlet.JspServlet.service:236
97,2005.07.14 12:17:23.812,javax.servlet.http.HttpServlet.service:802
99,2005.07.14 12:17:23.827,org.apache.catalina.core.ApplicationFilterChain.internalDoFilter:237
101,2005.07.14 12:17:23.827,org.apache.catalina.core.ApplicationFilterChain.doFilter:157
103,2005.07.14 12:17:23.827,org.apache.catalina.core.ApplicationDispatcher.invoke:704
105,2005.07.14 12:17:23.827,org.apache.catalina.core.ApplicationDispatcher.processRequest:474
107,2005.07.14 12:17:23.827,org.apache.catalina.core.ApplicationDispatcher.doForward:409
109,2005.07.14 12:17:23.827,org.apache.catalina.core.ApplicationDispatcher.forward:312

If the error occures in my servlet code, then I get class/method.line number. But the in the JSP I just get the above.

And all the browser requests go to servlets. The JSP's are not exposed to the user at all. By the time a JSP is called (forwarded to), everything should be present for use. I do check for null's, but only in the servlets (MVC).

I am getting these erros during development, where I more than likely will have errors on the first try.
 
Ahhh, MVC - great. A concept designed to hide errors. You're "MVC2" concept is probably actually hiding the error.

I know someonce at work who swears by MVC - to the letter.
Their webaap worked in dev, test, and uat.
It went live.
And died.
Their glorious MVC compiance meant they were (in effect) hiding their stack traces, only left with a log4j (oh help me please) trace that said something along the lines of "computer says no".
I said - "just stuff a scriplet-JSP into the webapp to replicate the code that is causing the error, and let the error come out in the stderr logs.
She said "No - I can't do that as MVC2 doesn't allow you to use scriptlet tags" !!!
I hung up the phone, hacked their wepabb in a manner that would leave any MVC2 man screaming, and came back 10 minutes later with the error.

A lesson for us all I think. MVC2 is great as a design principle, but it sure does hide problems.

Why oh why are you trying to manipulate the stack trace - why can you not just do :

myException.printStackTrace(System.err)

?

In short - print the real stack trace. If that doesn't work, then replicate the actual code thats barfing in a non-JSP-tag-wrapped manner, and you'll probably see the real error.

Good luck :)

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sigh. Yes MVC is nice and all, but I hate a lot of code mixed with HTML. So I use a servlet and JSP mix.

And as for the stack trace, that IS what I get:
Code:
StackTraceElement[] trace = fatal.getStackTrace();
which is what
Code:
myException.printStackTrace(System.err);
does.

The trace gets put into a log, the user gets a "Fatal Error" msg, I go to the log (online, I use a log parser), and there is the trace. The entire trace.

Doing this lets the user do something else (and others) without bringing down the app. It is the last ditch effort at catching exceptions. However, I am not here to get into a discussion about the merits of MVC.

I AM trying to find out just what "org.apache.jasper.JasperException" means, and where I can get more information about it. Sometimes it includes a line number (error code?).
 
Oh yes, I should add I did find the error (this time).

I forgot to put an object into the request attributes which the JSP was expecting. So when I tried to use the object, instant NullPointerException. But it would have been nice to know the line number.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top