How about something like this?
<%
data=bean1.getdata()
if (data==null) {
RequestDispatcher rd
application.getRequestDispatcher("/errorpage.jsp");
rd.forward(request, response);
}
if (data.equals("xyz")) {...} // This causes the exception if data is null
%>
I admit that this is modified from a servlet code, so I've never tried this
type of forwarding inside a JSP. I looked at page 74 in the book for the
info.
Also note that forwarding is different than redirecting. Redirecting sends
an HTTP message back to the browser, and the browser then requests the new
page. Forwarding takes place entirely server-side.