4

Error Page Handling In JSP

The error-page element declares a mapping between an error and a resource in the Web application that is called when that error occurs. Ther errors can be caused by HTTP errors (such as 404 Not Found) and Web application exceptions (like a ServletException). The errors can be mapped to any vali resource in the Web application, so it may be handled by a static HTML page, a JSP page, or a sevlet.

In web deployment descriptor put following

<web-app>
<error-page>
<error-code>404</error-code&gt
<location>/file-not-found.html<location>
</error-page>

<error-page>
<error-code>javax.servlet.ServletException</error-code&gt
<location>/oopsy.jsp<location>
</error-page>

.. while using action

<error-page>
<error-code>404</error-code&gt
<location>/showError.do<location>
</error-page>
</web-app>


|
0

How to check null String

First thing to remember is that the == operator compares two object references to see whether they refer to the same instance whereas equals() method compares the chars inside a String object.

Thus, str.equals(null) will always return false because there is no such object reference as null in reality.
So only str==null can help you.

However, a more strong way to check if a str object contains any char or not is

if str==null str.equals("")
{
...
}

Other way is just perform the operation on the str in a try-catch block catching the NullPointerException like
try {
str.substring(0, 2);
}catch(NullPointerException)
{
e.printStackTrace();
}

|

Copyright © 2009 So That I Can Remember All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.