Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
saima kanwal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alpesh Padra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes , i was overrding it without calling the superclass's init. I think that's the mistake. Thanks .
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The original point about having a single application-wide connection is still valid, though--really horrible, bad idea.
 
saima kanwal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i got the idea . thanks for correcting.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic