• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.servlet.ServletException: Exception creating bean of class

 
Gazelle Ahoo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I got the following error while running sample struts application. I would appreciate any help.
struts version= 1.1

error:
========
javax.servlet.ServletException: Exception creating bean of class struts1.form.TestActionForm: {1}
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.test.test_jsp._jspService(org.apache.jsp.test.test_jsp:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause
----------------------------------------------------------------------
test.jsp
===========

---------------------------------------------------------------------
struts-confif.xml
===================

------------------------------------------------------------------------
Action Class:
==============

-----------------------------------------------------------------------
Action Form Class:
====================

--------------------------------------------------------------
web.xml
===========
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags. Unformatted code/config/etc. is difficult to read. You can edit your post to include them using the button or re-post the question with proper formatting.

You didn't post the root cause of the exception, which would be helpful.
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, root cuase will tell the exact problem, meanwhile you can check this faq for the common cause.
 
Gazelle Ahoo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar,
Thank you for the useful link. I've copied the code above and I have done all the instructions, however it does not work. I really have been confused about problem. Is there any other reason for this problem?

 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gazelle you've still not provided the complete stack trace of the exception. You have been asked to provide the part of the stack trace below the root cause which might tell the exact cause of the exception...
 
Davie Lin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You should take out the save & delete method out of your ActionForm class
and create business class that handle the save and delete into the database.

I have never seen forms that has code to handle DB access, not good practice

 
Gazelle Ahoo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bellow is the complete errors. With regards to db handling, I always handle DB connection inside Form class and it works. I don't know how to handle it with business class; do you have sample source code about this?
My struts applications work well, I do not know what happens that they do not work any more. Is it possible that problem is connected to my struts library and tlds?


Complete stack trace from browswer:
-----------------------------------------------------------------------------------------------------------------
javax.servlet.ServletException: Exception creating bean of class struts1.form.TestActionForm: {1}
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.test.test_jsp._jspService(org.apache.jsp.test.test_jsp:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.jsp.JspException: Exception creating bean of class struts1.form.TestActionForm: {1}
org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:563)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
org.apache.jsp.test.test_jsp._jspx_meth_html_form_0(org.apache.jsp.test.test_jsp:149)
org.apache.jsp.test.test_jsp._jspx_meth_html_html_0(org.apache.jsp.test.test_jsp:120)
org.apache.jsp.test.test_jsp._jspService(org.apache.jsp.test.test_jsp:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


====================================================

Complete stack trace from console:
-----------------------------------------------------------------------------------------------------------------
Exception creating bean of class struts1.form.TestActionForm: {1}
at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:563)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
at org.apache.jsp.test.test_jsp._jspx_meth_html_form_0(org.apache.jsp.test.test_jsp:149)
at org.apache.jsp.test.test_jsp._jspx_meth_html_html_0(org.apache.jsp.test.test_jsp:120)
at org.apache.jsp.test.test_jsp._jspService(org.apache.jsp.test.test_jsp:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:626)
 
Davie Lin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take out the save() and delete() method and create another class

let's say TestActionDataBaseService.java in package struts1.DataBaseService

and pass in your Form or create a FormBean and pass them into save(ActionForm testForm) or delete(ActionForm testForm)
method in TestActionDataBaseService.java,

by the way, why is the save() return a string but in the action class



this doesn't seem compilable to me. am I missing something?

I would also recommend looking into PreparedStatment instead of Statement just in case if later on you have to write complex query.

Sorry, I don't really know what's wrong with the Exception, maybe the other Struts expert can help

Hope this helps
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Remove the "attribute" from the action mapping, its useless when you define the "name"
 
Gazelle Ahoo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you people for the recommendation. I understand that the problem is related to ReplicationDriver. The JSP page loads when I comment “ReplicationDriver driver = new ReplicationDriver();”
I’ve also created TestActionDataBaseService class according to Davie recommendation. The test.jsp page can be load but I getting error when I click “save” button. I am not sure whether or not got the intention properly. However, I’ve copied the updated save method and the stack trace bellow:

public class TestActionDataBaseService {



public class TestActionForm extends ActionForm {



Error
---------------------------------------------------------------------------------------
java.lang.NoClassDefFoundError: com/mysql/jdbc/ReplicationDriver
at struts1.form.TestActionForm.save(TestActionForm.java:69)
at struts1.action.TestAction.execute(TestAction.java:16)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:626)
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gazelle Ahoo wrote:
java.lang.NoClassDefFoundError: com/mysql/jdbc/ReplicationDriver


The error seems quite clear to me. The ReplicationDriver class is not found. See if the mysql jar file is in the WEB-INF/lib folder or not...
 
Gazelle Ahoo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help. That was exactly the point. The mysql connector jar file was outside of the lib folder.
Now it works well. Really thanks
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why they said TellTheDetails and don't make us guessing(like I did).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic