wood burning stoves 2.0*
The moose likes Struts and the fly likes overriding init() to make a database connection:nullpointer Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "overriding init() to make a database connection:nullpointer Exception" Watch "overriding init() to make a database connection:nullpointer Exception" New topic
Author

overriding init() to make a database connection:nullpointer Exception

saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
I am extending ActionServlet to override init() i order to make a the database connection with oracle. Previously I was making teh connection in each request, in the overridden action class and my application was working fine. But I think , the databse connection should be made once at the servlet initialization, and not at each request.

My overridden Action Servlet is :




my action class is :



web.xml is :




struts-config.xml is :




and the exception that i am getting is :

org.apache.jasper.JasperException: java.lang.NullPointerException: Module 'null' not found.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.NullPointerException: Module 'null' not found.
org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:755)
org.apache.struts.taglib.TagUtils.computeURLWithCharEncoding(TagUtils.java:364)
org.apache.struts.taglib.TagUtils.computeURLWithCharEncoding(TagUtils.java:285)
org.apache.struts.taglib.html.LinkTag.calculateURL(LinkTag.java:445)
org.apache.struts.taglib.html.LinkTag.doEndTag(LinkTag.java:353)
org.apache.jsp.index_jsp._jspx_meth_html_005flink_005f0(index_jsp.java:114)
org.apache.jsp.index_jsp._jspService(index_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.

please help me out.


SCJP 6.0 (86%) SCWCD 5 (94%)
Alpesh Padra
Ranch Hand

Joined: Jan 10, 2010
Posts: 41
It seems that your struts custom tag has some problem with attributes of <html:link/>. It might be you are missing some attributes.

Try to read specification for <html:link/> or send here your JSP code. so that we can identify the root cause.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Looks like you're accessing a JSP directly, instead of through an action.

So... there's a single connection, in the application context?! That will almost never work--what happens if you have more than a single user? Or a single user with multiple windows/tabs open? Consider connection pooling, otherwise you were better off the way you had it originally.

Even if you weren't, you should essentially never have to override the action servlet; for one-time application-startup tasks use a context listener.
saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
@ David Newton: thanks for your suggestion of using a context listener. I will try with that. I am not accessing any JSPs directly. My app was working fine before overriding this init().And everything is just the same except that i extend ActionServlet to override the init() and entering its name in web.xml.

So... there's a single connection, in the application context?! That will almost never work--what happens if you have more than a single user? Or a single user with multiple windows/tabs open? Consider connection pooling, otherwise you were better off the way you had it originally.


I do not understand what you mean by single connection? can you please explain and tell me how to implement a pool of connections??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you overriding it without calling the superclass's unit?!

Search the web for connection pooling first-if you have specific questions you can start up a new thread.
saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
Oh yes , i was overrding it without calling the superclass's init. I think that's the mistake. Thanks .
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The original point about having a single application-wide connection is still valid, though--really horrible, bad idea.
saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
ok i got the idea . thanks for correcting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding init() to make a database connection:nullpointer Exception
 
Similar Threads
java.lang.ClassNotFoundException: org.apachi.struts.action.ActionServlet
a question about struts....please help
error in my struts application no getter methods
Configuring First Struts Application
java.lang.NullPointerException in a simple servlet