wood burning stoves 2.0*
The moose likes Struts and the fly likes Exception creating a bean of class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Exception creating a bean of class" Watch "Exception creating a bean of class" New topic
Author

Exception creating a bean of class

kranti kumar
Greenhorn

Joined: Dec 31, 2008
Posts: 10
Hi friends,

I got the follwing error when I am trying to run my struts application in eclipse.


ERROR::

/******************************


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Exception creating bean of class net.com.struts.form.RegForm: {1}
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.reg_jsp._jspService(reg_jsp.java:95)
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:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

javax.servlet.jsp.JspException: Exception creating bean of class net.com.struts.form.RegForm: {1}
org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:563)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
org.apache.jsp.reg_jsp._jspx_meth_html_005fform_005f0(reg_jsp.java:112)
org.apache.jsp.reg_jsp._jspService(reg_jsp.java:85)
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:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

***************************************/

My project contains:: reg.jsp , RegForm , RegAction , pass.jsp , fail.jsp, web.xml , struts-config.xml.

code:: reg.jsp contains::

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<HTML>
<BODY>
<html:form action="/reg1">
<bean:message key="label.firstName"/>
<html:text property="label.firstName"></html:text>
<html:errors property="label.firstName"></html:errors>

<bean:message key="label.lastName" />
<html:text property="label.lastName"></html:text>
<html:errors property="label.lastName"></html:errors>

<bean:message key="label.userName" />
<html:text property="label.userName"></html:text>
<html:errors property="label.userName"/>

<bean:message key="label.password"/>
<html:text property="label.password" />
<html:errors property="label.password"/>

<bean:message key="label.repassword"/>
<html:text property="label.repassword" />
<html:errors property="label.repassword"/>

<html:submit></html:submit>
<html:cancel />
</html:form>
</BODY>
</HTML>


code:: web.xml contains::

<?xml version="1.0" encoding="UTF-8"?>

<web-app>
<display-name>RealEstate</display-name>
<welcome-file-list>
<welcome-file>reg.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>


</web-app>


code:: struts-config.xml contains::

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
<form-beans>
<form-bean name="regform" type="net.com.struts.form.RegForm" />
</form-beans>
<action-mappings>
<action path="/reg1"
name="regform"
validate="true"
input="/reg.jsp"
type="net.com.struts.action.RegAction">
<forward name="success" path="/pass.jsp" />
<forward name="failure" patj="/fail.jsp" />
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>


code:: RegForm.java contains::

package net.com.struts.form.RegForm;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class RegForm extends ActionForm
{

private String firstName , lastName , userName , password , repassword;

public ActionErrors validate(ActionMapping mapping , HttpServletRequest request)
{
ActionErrors actionerrors=new ActionErrors();

if(firstName==null||firstName.trim().equals(""))
{
actionerrors.add("firstName",new ActionMessage("error.firstName.required"));
}
if(lastName==null||lastName.trim().equals(""))
{
actionerrors.add("lastName",new ActionMessage("error.lastName.required"));
}
if(userName==null||userName.trim().equals(""))
{
actionerrors.add("userName",new ActionMessage("error.userName.required"));
}
if(password==null||password.trim().equals(""))
{
actionerrors.add("password",new ActionMessage("error.password.required"));
}
if(repassword==null||repassword.trim().equals(""))
{
actionerrors.add("repassword",new ActionMessage("error.repassword.required"));
}
return actionerrors;
}
public void setfirstName(String firstName)
{
this.firstName=firstName;
}
public void setlastName(String lastName)
{
this.lastName=lastName;
}
public void setuserName(String userName)
{
this.userName=userName;
}
public void setpassword(String password)
{
this.password=password;
}
public void setrepassword(String repassword)
{
this.repassword=repassword;
}
public String getfirstName()
{
return firstName;
}
public String getlastName()
{
return lastName;
}
public String getuserName()
{
return userName;
}
public String getpassword()
{
return password;
}
public String getrepassword()
{
return repassword;
}


}


please anyone can solve my problem. I donot what was wrong with my code.
Any help is appreciable.

Thanking you.



......
kranthi
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Have you looked at this Struts FAQ entry ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
kranti kumar
Greenhorn

Joined: Dec 31, 2008
Posts: 10
Hi sagar,

I have gone through Stuts FAQ, but that one couldnot solve my error.

Any one is appreciate to solve this error.


......
kranthi
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Pl check the CLASSPATH, make sure that, the action form "RegForm" must resides in WEB-INF\classes\net\com\struts\form\RegForm directory (If you are using Tomcat).
kranti kumar
Greenhorn

Joined: Dec 31, 2008
Posts: 10
Hi sagar,

The CLASSPATH and directory structure is fine. But I donot know why this error occured.

any how thanks for you.

any help is appreciated.


.......
kranthi
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Why do "properties" attribute of html:form tag like this,



PL specify the properties name SAME as that defined in ActionForm,

Correct :

kranti kumar
Greenhorn

Joined: Dec 31, 2008
Posts: 10
Hi sagar,

Again Thanking you for your help, but still i am unable to find out what is the wrong with my code.

If you donot mind can you little bit explain more.

I am unable to find the difference between my code and code posted by you.


.....
kranthi
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by kranti kumar:

If you donot mind can you little bit explain more.

I am unable to find the difference between my code and code posted by you.


The difference lies in the way you defined "property" attribute in html:text tag. You are supposed to take text field value in underlying bean (RegForm) variable, like in firstName, lastName, etc

Here is Form properties/varaible,


I just want you to replace your existing JSP(reg.jsp) code with the modified JSP which I posted earlier.

Let me know whether this works or not .
kranti kumar
Greenhorn

Joined: Dec 31, 2008
Posts: 10
Hi sagar,

Still the application is not working . Again it is showing same error.


Thanking you.


.......
kranthi
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I don't know whether this works , but this is the issue related to Struts 1.1, but I'm not sure .

Just give it a try ,

Just comment the validate method,



comment the whole method body and re run.

Lastly, Which version of Struts you are using ?
May be we are missing any Struts libraries , make sure you get all the basic Struts libraries of version you are using !!
Janardhan Mudduluru
Greenhorn

Joined: Jul 09, 2009
Posts: 4
Sagar Rohankar wrote:Pl check the CLASSPATH, make sure that, the action form "RegForm" must resides in WEB-INF\classes\net\com\struts\form\RegForm directory (If you are using Tomcat).


Thanks a Bunch....I was searching for this solution....it really helped me.
Much Appreciated.
jyotiprakash paikaray
Greenhorn

Joined: Jul 26, 2012
Posts: 1
Actually i got the same problem when i am doing it manually (without any IDE) and for not putting the .class file in classes folder..
so check out whether you put .classes files in classes folder after compiling it..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception creating a bean of class
 
Similar Threads
No tag "form" defined in tag library imported with prefix "html"
"No getter method for property ..." error
ERROR :: cannot find ActionMappings or ActionFormBeans
SwitchAction Query
Exception creating bean of class