struts validation error

Posted on 2012-08-16
Last Modified: 2012-08-17
I was trying struts validation example. When I try to run jsp like


It is giving error as below, attachment.

Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance

HTTP Status 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve definition for form bean: "CustomerForm" on action: "customer"


type Exception report

message javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve definition for form bean: "CustomerForm" on action: "customer"

description The server encountered an internal error (javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve definition for form bean: "CustomerForm" on action: "customer") that prevented it from fulfilling this request.


org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve definition for form bean: "CustomerForm" on action: "customer"

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve definition for form bean: "CustomerForm" on action: "customer"

Below URL with  directly going to confirmation.jsp without going through jsp, form bean.
CustomerDetails.jsp looks like

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
      <html:errors />
      <P>Please fill in the following details</P>
      <html:form action="customer">
            <TABLE border="1">
                              <TD><html:text property="firstName"></html:text>
                              <TD><html:text property="middleName"></html:text>
                              <TD><html:text property="lastName"></html:text>
                              <TD><html:text property="age"></html:text>
                              <TD><html:text property="ssn"></html:text>
                              <TD><html:text property="city"></html:text>
                              <TD><html:text property="satte"></html:text>
                              <TD><html:text property="country"></html:text>
                              <TD colspan="2"><html:submit></html:submit>

Action class looks like

package 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 formbeans.CustomerForm;
public class CustomerAction extends Action {
      public ActionForward execute(ActionMapping mapping, ActionForm form,
                  HttpServletRequest request, HttpServletResponse response)
      throws Exception {
            ActionErrors errors = new ActionErrors();
            CustomerForm customerForm = (CustomerForm) form;
            try {
                              customerForm.getMiddleName(), customerForm.getLastName(),
                              customerForm.getAge(),customerForm.getSsn(), customerForm.getCity(),
                              customerForm.getState(), customerForm.getCountry());
            } catch (Exception e) {
                  // Report the error using the appropriate name and ID.
                  errors.add("name", new ActionError("id"));
            return (mapping.findForward("success"));
      private void insertCustomerRecord(String firstName, String middleName,
                  String lastName, String age, String ssn, String city, String state,      
              String country) {

FormBean Looks like

package formbeans;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionError;
public class CustomerForm extends ActionForm {
      private String ssn = null;
      private String age = null;
      private String country = null;
      private String state = null;
      private String middleName = null;
      private String firstName = null;
      private String city = null;
      private String lastName = null;
      public String getAge() {
            return age;
      public void setAge(String age) {
            this.age = age;
      public String getCity() {
            return city;
      public void setCity(String city) {
   = city;
      public String getCountry() {
            return country;
      public void setCountry(String country) {
   = country;
      public String getFirstName() {
            return firstName;
      public void setFirstName(String firstName) {
            this.firstName = firstName;
      public String getLastName() {
            return lastName;
      public void setLastName(String lastName) {
            this.lastName = lastName;
      public String getMiddleName() {
            return middleName;
      public void setMiddleName(String middleName) {
            this.middleName = middleName;
      public String getSsn() {
            return ssn;
      public void setSsn(String ssn) {
            this.ssn = ssn;
      public String getState() {
            return state;
      public void setState(String state) {
            this.state = state;
      public ActionErrors validate(ActionMapping mapping, HttpServletRequest
                  request) {
            ActionErrors errors = new ActionErrors();
            if ((lastName == null) || (lastName.length() == 0)) {
                  errors.add("lastName", new ActionError("error.lastName.required"));
            if ((ssn == null) || (ssn.length() == 0)) {
                  errors.add("ssn", new ActionError("error.ssn.required"));
            // Validation for valid values for SSN and Age
            try {
                  int ssn1 = Integer.parseInt(ssn);
            } catch (Exception e) {
                  // If it comes here, then the user entered non-numeric data for SSN
                  errors.add("ssn_number", new ActionError("error.ssn.invalid"));
            try {
                  int age1 = Integer.parseInt(age);
            } catch (Exception e) {
                  errors.add("age_number", new ActionError("error.age.invalid"));
            return errors;

Struts -Config.xml looks like

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 1.1//EN"
      <!-- Data Sources -->
      <!-- Form Beans -->
            <form-bean name="loginForm" type="formbeans.LoginForm">

      <!-- Global Exceptions -->
      <!-- Global Forwards -->
      <!-- Action Mappings -->
            <action path="/customer" name="CustomerForm" validate="true"
                  input="/jsps/struts/CustomerDetails.jsp" scope="request"
                  <forward name="success" path="/jsps/struts/Confirmation.jsp" />


            <action path="/welcome" forward="/jsps/struts/Welcome.jsp" />
            <action path="/maintenance" type="actions.MaintenanceAction">
                  <forward name="sales" path="/jsps/struts/Sales.jsp" />
                  <forward name="inventory" path="/jsps/struts/Inventory.jsp" />
            <action path="/login" name="loginForm" type="actions.LoginAction">
                  <forward name="success" path="/jsps/struts/Main.jsp" />
            <action path="/customTags" type="actions.BeanAction">
                  <forward name="bean" path="/jsps/struts/BeanTagsDemo.jsp" />
      <!-- Message Resources -->
      <message-resources parameter="myprops.MyStruts" />

Question by:gudii9
    1 Comment
    LVL 10

    Accepted Solution

    add the following under <form-beans> tag
     <form-bean name="customerForm" type="formbeans.CustomerForm">

    And change
           <action path="/customer" name="customerForm" validate="true"
                      input="/jsps/struts/CustomerDetails.jsp" scope="request"
                      <forward name="success" path="/jsps/struts/Confirmation.jsp" />


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    The viewer will learn how to implement Singleton Design Pattern in Java.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now