• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

"Cannot retrieve definition for form bean" error

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks it s helpful
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic