aspose file tools*
The moose likes Struts and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark ""Cannot retrieve definition for form bean" error" Watch ""Cannot retrieve definition for form bean" error" New topic
Author

"Cannot retrieve definition for form bean" error

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I'm getting the following error when I first bring up my web app and I cannot trace down where the culprit is. I've triple checked my Action Form properties to ensure I'm following the "bean law" but I can't uncover where the error may be ocurring. Any suggestions would be greatly appreciated (I've narrowed down the code as much as I could):

Error:

org.apache.jasper.JasperException: Cannot retrieve definition for form bean loginForm on action /validateLogin


struts-config.xml:

<struts-config>
<form-beans>
<form-bean>name="loginForm" type="com.product.form.LoginForm"</form-bean>
</form-beans>
<action-mappings>
<action path="/displayLogin"
forward="/WEB-INF/jsp/displayLogin.jsp">
</action>
<action path="/validateLogin"
name="loginForm"
type="com.product.action.ValidateLogin"
input="WEB-INF/jsp/displayLogin.jsp"
scope="request">
<forward name="success" path="WEB-INF/jsp/mainScreen.jsp"/>
<forward name="failure" path="WEB-INF/jsp/invalidLogin.jsp"/>
</action>
</action-mappings>
<message-resources parameter="ApplicationResources"/>
</struts-config>

Here's the JSP page I'm trying to access (displayLogin.jsp):

<%@ taglib uri="/tags/struts-html" prefix="html" %>

<html>
<body>
<h1 align="center"><B>Project X (with Struts)</B></h1>
<html:errors/>
<html:form action="/validateLogin">
<table>
<tr><td>User Name:</td><td><html:text property="username"/></td></tr>
<tr><td>Password:</td><td><html assword property="password"/></td></tr>
</table>
<center>
<html:submit> Login </html:submit>
</center>
</html:form>
</body>
</html>

and finally, here's the Action Form:

package com.product.form;

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

public class LoginForm extends ActionForm {

private String username;
private String password;

//Getters and Setters

public void setUsername (String username) {
this.username = username;
}

public String getUsername () {
return username;
}

public void setPassword (String password) {
this.password = password;
}

public String getPassword () {
return password;
}

//Override the validate method

public ActionErrors validate (ActionMapping mapping,
HttpServletRequest request) {

ActionErrors actionerrors = new ActionErrors();

if (username.equals("")) {
actionerrors.add("no.username", new ActionMessage("no.username"));
}
if (password.equals("")) {
actionerrors.add("no.password", new ActionMessage("no.password"));
}

return actionerrors;

} //End validate

} //end LoginForm



Can anyone point me in the right direction. Oh yeah, my environment is run of the mill: WindowsXP, Tomcat 5, Struts 1.1

Thanks in advance,
Scott
Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
Ok, I noticed that there were some issues with my struts-config.xml (I was missing a "/" in a couple of forward statements). When I make the change and re-run, I get the following:

New struts-config.xml:

<?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="loginForm" type="com.product.form.LoginForm" </form-bean>
</form-beans>
<action-mappings>
<action path="/displayLogin"
forward="/WEB-INF/jsp/displayLogin.jsp">
</action>
<action path="/validateLogin"
name="loginForm"
type="com.product.action.ValidateLogin"
input="/WEB-INF/jsp/displayLogin.jsp"
scope="request">
<forward name="success" path="/WEB-INF/jsp/mainScreen.jsp"/>
<forward name="failure" path="/WEB-INF/jsp/invalidLogin.jsp"/>
</action>
</action-mappings>
<message-resources parameter="ApplicationResources"/>
</struts-config>


and here's the error out of Tomcat:

exception

org.apache.jasper.JasperException: Exception in JSP: /WEB-INF/jsp/displayLogin.jsp:7

4: <body>
5: <h1 align="center"><B>Project X (with Struts)</B></h1>
6: <html:errors/>
7: <html:form action="/validateLogin">
8:
9: <table>
10: <tr><td>User Name:</td><td><html:text property="username"/></td></tr>


root cause

javax.servlet.ServletException: Cannot retrieve definition for form bean loginForm on action /validateLogin

I apologize for the confusion with the struts-config.xml oversight.

Thanks, again.
Scott
Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I fixed the issue by changing the struts-config.xml file. THe form bean tags were written incorrectly.

Correct Version:

<form-beans>
<form-bean name="loginForm" type="com.product.form.LoginForm"/>
</form-beans>

Not

<form-bean>name="loginForm" type="com.product.form.LoginForm"</form-bean>

Please close this issue.
Divyalakshmi sadasivam
Greenhorn

Joined: Dec 04, 2012
Posts: 2
Scott Updike wrote:I fixed the issue by changing the struts-config.xml file. THe form bean tags were written incorrectly.

Correct Version:

<form-beans>
<form-bean name="loginForm" type="com.product.form.LoginForm"/>
</form-beans>

Not

<form-bean>name="loginForm" type="com.product.form.LoginForm"</form-bean>

Please close this issue.
Divyalakshmi sadasivam
Greenhorn

Joined: Dec 04, 2012
Posts: 2
thanks it s helpful
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: "Cannot retrieve definition for form bean" error