cannot find bean in any scope error

From: raj (rchekuri_at_gmail.com)
Date: 02/28/05


Date: 28 Feb 2005 11:12:21 -0800

I have a small sample application which has 2 jsps and an action form
an action class and the config files. In the input jsp page which is
"Register.jsp" I have fields for first name, last name and alias. In
the output jsp which is "thankyou.jsp" I'm printing the firstname(using
bean:write) taken as input from "register.jsp"
I'm getting the error:
"Error 500: Cannot find bean registrationFormBean in any scope"

My files:

struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!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>

        <!-- Data Sources -->
        <data-sources>
        </data-sources>

        <!-- Form Beans -->
        <form-beans>
                <form-bean name="registrationFormBean"
type="com.webagesolutions.struts.forms.RegistrationFormBean">
                </form-bean>
        </form-beans>

        <!-- Global Exceptions -->
        <global-exceptions>
        </global-exceptions>

        <!-- Global Forwards -->
        <global-forwards>
        </global-forwards>

        <!-- Action Mappings -->
        <action-mappings>
                <action name="registrationFormBean" path="/register" scope="request"
type="com.webagesolutions.struts.actions.Register"
input="register.jsp">
                        <forward name="success" path="/thankyou.jsp" redirect="true">
                        </forward>
                        <forward name="failure" redirect="false" path="/register.jsp">
                        </forward>
                </action>
        </action-mappings>

        <!-- Message Resources -->
        <message-resources
parameter="com.webagesolutions.struts.resources.ApplicationResources"/>

</struts-config>

register.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="style***"
        type="text/css">
<TITLE></TITLE>
</HEAD>

<BODY>
<html:form action="/register.do">
<table align="center">
   <tr>
     <td>
     First Name:</td>
     <td>
    <html:text property="fname"></html:text></td>
   </tr>
   <tr>
     <td>
     Last Name:</td>
     <td><html:text property="lname"></html:text></td>
   </tr>
   <tr>
     <td>Alias:</td>
     <td><html:text property="alias"></html:text></td>
   </tr>
   <tr>
     <td><html:submit>Submit</html:submit></td>
     <td><html:reset>Reset</html:reset></td>
   </tr>
</table>
</html:form>

</BODY>
</html:html>

thankyou.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="style***"
        type="text/css">
<TITLE></TITLE>
</HEAD>

<BODY>
Thank You!

<bean:write name="registrationFormBean" property="fname"/>

</BODY>
</html:html>

RegistrationFormBean.java

package com.webagesolutions.struts.forms;

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

/**
 * Form bean for a Struts application.
 * @version 1.0
 * @author
 */
public class RegistrationFormBean extends ActionForm {

        private String lname = null;
        private String fname = null;
        private String alias = null;

        /**
         * Get lname
         * @return String
         */
        public String getLname() {
                return lname;
        }

        /**
         * Set lname
         * @param <code>String</code>
         */
        public void setLname(String a) {
                this.lname = a;
        }

        /**
         * Get fname
         * @return String
         */
        public String getFname() {
                return fname;
        }

        /**
         * Set fname
         * @param <code>String</code>
         */
        public void setFname(String n) {
                this.fname = n;
        }

        /**
         * Get alias
         * @return String
         */
        public String getAlias() {
                return alias;
        }

        /**
         * Set alias
         * @param <code>String</code>
         */
        public void setAlias(String c) {
                this.alias = c;
        }

        public void reset(ActionMapping mapping, HttpServletRequest request) {

                // Reset values are provided as samples only. Change as appropriate.

        fname = "";
        lname = "";
        alias = "";

}

        public ActionErrors validate(
                ActionMapping mapping,
                HttpServletRequest request) {

                ActionErrors errors = new ActionErrors();
                // Validate the fields in your form, adding
                // adding each error to this.errors as found, e.g.

                // if ((field == null) || (field.length() == 0)) {
                // errors.add("field", new
org.apache.struts.action.ActionError("error.field.required"));
                // }
                return errors;

        }
}

Register.java
package com.webagesolutions.struts.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.webagesolutions.struts.forms.RegistrationFormBean;

/**
 * @version 1.0
 * @author
 */
public class Register extends Action {

        public ActionForward execute(
        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) throws Exception
        {

        ActionErrors errors = new ActionErrors();
        ActionForward forward = new ActionForward();
        RegistrationFormBean reg = (RegistrationFormBean) form;
                try{
        //if (!errors.empty()) {
        // saveErrors(request, errors);
        System.out.println("success");
                forward = mapping.findForward("success");
                }
         catch(Exception e){
                forward = mapping.findForward("failure");
        }
        return (forward);
}

}

can someone help me with this error?


Quantcast