File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Error: creating bean of class (HELP THE NEWBE) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Error: creating bean of class (HELP THE NEWBE)" Watch "Error: creating bean of class (HELP THE NEWBE)" New topic
Author

Error: creating bean of class (HELP THE NEWBE)

Wendy Baur
Greenhorn

Joined: Mar 01, 2005
Posts: 13
Hello All,

Error: javax.servlet.servletException: Exception creating bean of class java.ActionForm.Security.authenticateActionForm

LOGIN.JSP
<html:form action="pages/Security/authenticate.do method="post" focus="userName">

(the other typical stuff is included here)


STRUTS-CONFIG.XML
<form-beans>
<form-bean
name="authenticate"
type="java.ActionForm.Security.authenticateActionForm">
<form-property name="userName" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
</form-bean>
</form-beans>

<global-forwards>
<forward name="login" path="Login.do"/>
</global-forwards>

<action-mappings>
<action
path="/Login"
forward="/pages/Security/Login.jsp"/>

<action
path="/pages/Security/authenticate"
type="java.Action.Security.LoginAction"
name="authenticate"
input="pages/Security/Login"
scope="request"
validate="true">
<forward name="Success" path="pages/Security/index2.jsp"/>
<forward name="Failure" path="pages/Security/invalid.jsp"/>
</action>

</action-mappings>

WEB.XML
<display-name>Handlayout</dislay-name>

<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>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>/pages/index.jsp</welcome-file>
</welcome-file-list>

THE USUAL TAG-LIB'S ARE INCLUDED
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Okay

1. For html:form, the action property shouldn't include the action extension. It should just be the name of the action like you have it in your struts-confix.xml file.

2. You don't need to use the form-property elements when you define your form unless the form type is a DynaActionForm, or one of its subtypes. I'm not sure if Struts cares if you use form-property with regular ActionForms -- which it should figure out by reflection and so forth.

3. Try those ... if they don't work, give us a stack trace.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Wendy Baur
Greenhorn

Joined: Mar 01, 2005
Posts: 13
I made the suggested changes and here's the stack trace as it appears in server.log (JBoss)

2005-03-11:03:17,311 ERROR [org.apache.struts.util.RequestUtils] Error creating form bean of class java.ActionForm.Security.authenticateActionForm

java.lang.NullPointerException at
org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:214)
at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:294)
at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:193)
at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:453)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:433)
at org.apache.jsp.pages.Security.Login_jsp_jspx_meth_html_form_0(Login_jsp.java:155)
at org.apache.jsp.pages.Security.Login_jsp_jspx_meth_html_html_0(Login_jsp.java:114)
at org.apache.jsp.pages.Security.Login_jspService(login_jsp.java:78)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.jspServletWrapper.service(jspServletWrapper.java:324)
at org.apache.jasper.servlet.jJspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(applicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.ApplicationDispatcheer.invoke(ApplicationDispatcher.java:704)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:747)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:994)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(tilesRequestProcessor.java:343)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:553)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:211)
at org.apache.struts.action.ActionServletProcess(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internationalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilber(ReplyHeaderFilter.java:75)
at org.apache.catalina.core.AppplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValue.invoke(StandardWrapperValue.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValueContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValue.invokeInternal(StandardContextValue.java:198)
at apache.catalina.core.StandardContextValve.invoke(StandardContextValue.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.jaccContextValve.invoke(JaccContextValve.java:54)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.Standard.ValveContext.invlkeNext(StandardValveContextljava:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)


ROOT CAUSE:
javax.servlet.jsp.jspException:Exception creating bean of class java.ActionForm.Security.authenticateActionForm:

org.apache.struts.taglib.html.FormTag.initFormBean (FormTag.java:463)
org.apache.struts.taglib.html.Formtag.doStartTag(FormTag.java:433)
org.apache.jsp.pages.Security.Login_jsp_jspx_meth_html_form_0(Login_jsp.java:155)
org.apache.jsp.page.Security.Login_jsp._jspx_meth_html_thml_0(Login_jsp.java:114)
org.apache.jsp.pages.Security.Login_jsp._jspServlce(Login_jsp.java:78)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Your form-bean element refers to a class named "authenticateActionForm". I suspect that it should be "AuthenticateActionForm".
[ March 01, 2005: Message edited by: Jason Menard ]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4991
    
    8

Wendy, if it's not too long, please post the code (or some of the major sections) of your ActionForm.

Also, a note about naming conventions: package names are usually all lowercase while class names are usually in camel caps, i.e. the first letters of each word making up the class name is capitalized and the rest is lower case. For example: ActionForm or AuthenticateUserForm.

Following standard naming conventions, the fully qualified class name of your form would be java.actionform.security.AuthenticateActionForm (although it's also a tacit "rule" that the java root package is reserved for the core Java classes written by Sun)


Junilu - [How to Ask Questions] [How to Answer Questions]
Wendy Baur
Greenhorn

Joined: Mar 01, 2005
Posts: 13
My Action and ActionForm are very basic...

ACTION:
package java.Action.Security;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponce;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action
import javax.servlet.ServletContext;

public class LoginAction extends Action
{
public ActionForward execute(ActionMapping actiomMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse)
{
return (actionMapping.findForward("failure"));
}
}


ACTION FORM:
package java.ActionForm.Security;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletContext;

public class authenticateActionForm extends ActionForm
{
protected String userName = null;
protected String password = null

public void setUserName(String userName)
{
this.userName = userName;
}
public String getUserNme()
{
return (this.userName);
}
public void setPassword(String password)
{
this.password = password;
}
public void getPassword()
{
return (this.password);
}

public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest)
{
ActionErrors errors = new ActionErrors();

if(getUserName() == null || getUserName().length() < 1)
{
errors.add("userName", new ActionMessage("Security.error.userName.required"));
}
if(getPassword() == null || getPassword().length() < 1)
{
errors.add("password" , new ActionMessage("Security.error.password.reuired"));
}

return errors;
}
public void reset(ActionMapping actionMapping, HttpServletRequest servletRequest)
{
this.userName = "";
this.password = "";
}
}
[ March 02, 2005: Message edited by: Wendy Baur ]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
When posting code, please use the UBB CODE tags, and remember to disable smilies.

If the code for your ActionForm is exactly what you are trying to use, there are a couple problems with it, and it probably shouldn't even compile.



The line of code...

protected String password = null

...is missing a semicolon at the end. Without it you should be getting a compilation error.

The method declaration...

public String getUserNme()

...should be getUserName(). You refer to getUserName() in your vlidate() method, and since it doesn't exist you should get a compilation error.

Speaking of the validate() method, you are trying to create a new ActionMessage with the key Security.error.password.reuired, which I suspect should really be Security.error.password.required.

So here's what's probably happening... You are getting compilation errors when you try to compile the ActionForm. Since the class does not exist since it can't be compiled, you are receiving the error you are getting, which is that it can't be created when you want to use it.

Also, you might seriously want to take to heart what Junilu said about Java package and class naming conventions. While the compiler won't enfore them, they are standards.
Wendy Baur
Greenhorn

Joined: Mar 01, 2005
Posts: 13
The errors you are speaking of are actually typos. Unfortunately I work in an environment where I can not copy and paste code I have to retype it. Please look for other possible issues
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4991
    
    8

In situations like yours, it's sometimes just best to start with the most basic things that can go wrong. If the actual code does indeed compile, make sure that the deployed WAR file has the .class file in it and that it is in the proper directory (should be in one where the full path that reflects the package names you use). If that checks out, what IDE are you using, if any, and what tool/command are you using to create the WAR file and deploy it?
Wendy Baur
Greenhorn

Joined: Mar 01, 2005
Posts: 13
My issue has been resolved. THANKS FOR YOUR HELP EVERYONE
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4991
    
    8

Good to hear. Out of curiosity, would you mind sharing some details of the resolution?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error: creating bean of class (HELP THE NEWBE)