struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yee, Richard K,,DMDCWEST" <Ye...@osd.pentagon.mil>
Subject [OT] Handling database connection exceptions
Date Tue, 18 Nov 2003 00:07:10 GMT
Shyam,
This problem is not happing in your JSP. According to your stack trace, it
happens in obs.business.UserLogin.checkLogin(UserLogin.java:192) which is
being called in your LoginAction.perform().

I think you should translate the NullPointerException generated in your
checkLogin method to a more meaningful exception (ie.
DatabaseUnavailableException) and catch it in your perform() method. You can
then redirect to an error page from there.

-Richard



500 Internal Server Error
java.lang.NullPointerException
	at
obs.business.UserLogin.checkLogin(UserLogin.java:192)

-----Original Message-----
From: Shyam A [mailto:struts_newbie@yahoo.com] 
Sent: Monday, November 17, 2003 3:53 PM
To: Struts Users Mailing List
Cc: Yeerk@osd.pentagon.mil
Subject: RE: [OT] Handling database connection exceptions


Richard,

Thanks for your mail. I am pretty sure I don't access
the database in my JSP's. I also use the "errorPage"
attribute for all my JSP's, however, it does not
handle "Null Pointer" exceptions that occur due to
problems with database connection.

Given below is the Exception trace...it occurs when I
try to logon to my application when my database is
down. Btw, I use an Action class for processing user
login. (I use DispatchAction class for all other
operations)

######################################
500 Internal Server Error
java.lang.NullPointerException
	at
obs.business.UserLogin.checkLogin(UserLogin.java:192)
	at
obs.application.LoginController.checkLogin(LoginController.java:37)
	at
obs.application.action.LoginAction.perform(LoginAction.java:91)
	at
org.apache.struts.action.Action.execute(Action.java:415)
	at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
sor.java:465)
	at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
	at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1422)
	at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:523)
	at
javax.servlet.http.HttpServlet.service(HttpServlet.java:211)
	at
javax.servlet.http.HttpServlet.service(HttpServlet.java:309)
	at
javax.servlet.http.HttpServlet.service(HttpServlet.java:336)
	at com.evermind[Oracle9iAS (1.0.2.2) Containers for
J2EE].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.j
ava:501)
	at com.evermind[Oracle9iAS (1.0.2.2) Containers for
J2EE].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDis
patcher.java:170)
	at com.evermind[Oracle9iAS (1.0.2.2) Containers for
J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:
576)
	at com.evermind[Oracle9iAS (1.0.2.2) Containers for
J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:189)
	at com.evermind[Oracle9iAS (1.0.2.2) Containers for
J2EE].util.ThreadPoolThread.run(ThreadPoolThread.java:62)

###########################################

As you would notice above, the Exception is propagated
from a class in the "model" - UserLogin.
I noticed that the UserLogin class catches only
"SQLException", which is why I guess the "NullPointer" exception is
propagated to my Action class. Again, the
perform() method of the Action class throws
"Exception" but does not "catch" it.

What do you think would be a graceful solution to this
problem? Pardon my ignorance!

Thanks,
Shyam


--- "Yee, Richard K,,DMDCWEST"
<Yeerk@osd.pentagon.mil> wrote:
> Shyam,
> Where in your JSP does the NullPointerException
> occur? Is it in a method
> call in a scriptlet? If so, your JSP is still
> indirectly accessing the
> database. What Wendy suggested was that the the
> database access class be
> invoked from your DisplactAction class and the
> results be put in a
> collection and set as an attribute in the request.
> That way, any problems
> with getting the data would be caught in your Action
> class and then you
> could forward to an error page.
> 
> Otherwise, why can't you just specify an error page
> using the errorPage
> attribute in your JSP's <%@page ...> tag?
> 
> -Richard
> 
> -----Original Message-----
> From: Shyam A [mailto:struts_newbie@yahoo.com]
> Sent: Monday, November 17, 2003 3:10 PM
> To: Struts Users Mailing List
> Cc: Wendy.Smoak@asu.edu
> Subject: RE: [OT] Handling database connection
> exceptions
> 
> 
> Wendy,
> 
> Thanks for your mail. I don't know if you fully
> understood where I'm coming from! As I said, the
> database connection is accessed from a Data Access
> class (read model), which is called from my
> DispatchAction class. Since the exception is not
> caught in my DispatchAction class (the methods throw Exception), it is 
> propagated to my JSP's. It doesn't mean my JSP's directly access the
> database!
> 
> Anyway, thanks for your help.
> 
> Shyam
> 
> 
> --- Wendy Smoak <Wendy.Smoak@asu.edu> wrote:
> > > I have a Database servlet configured in web.xml,
> > which
> > > intialises a connection pool on Server startup.
> > > However, if the data source is unavailable, I
> get
> > a
> > > "Null Pointer" exception on my JSPs, which is
> > > propagated from my Data Access class.
> > 
> > IMO, the problem is that you're accessing the
> > database from the JSP.
> > And this, in a Struts webapp?!  The view has no
> > business talking to the
> > model.
> > 
> > If you move the data access to the Action, then
> you
> > can catch the error
> > and gracefully forward to an error page.
> > 
> > Meanwhile, you can define error pages in web.xml
> so
> > that your users
> > don't see the stack trace.  For example, I have
> > this:
> >    <error-page>
> >      
> >
>
<exception-type>javax.servlet.ServletException</exception-type>
> >      
> >
>
<location>/WEB-INF/jsp/exceptionServlet.jsp</location>
> >    </error-page>
> > which gives the user an apology and a phone number
> > to call.
> > 
> > --
> > Wendy Smoak
> > Applications Systems Analyst, Sr.
> > Arizona State University, PA, IRM
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > 
> 
> 
> __________________________________
> Do you Yahoo!?
> Protect your identity with Yahoo! Mail AddressGuard
> http://antispam.yahoo.com/whatsnewfree
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message