JavaSercer Pages Example 5.3 shows the (Mambo hosting) JSP page

JavaSercer Pages Example 5.3 shows the JSP page that is invoked when the user submits the form. Example 5.3. A JSP Page that Validates User Input with a Bean (userinfo1.jsp) <%@ page language="java" contentType="text/html" %> The following information was saved:

  • User Name:
  • Birth Date:
  • Email Address:
  • Sex:
  • Lucky number:

The user input is valid: Almost at the top of Example 5.3, you see that a action is used to associate a name with the bean: The action looks similar to the one in Example 5.1. The id attribute specifies the name for the bean, and the class attribute specifies the full name of the bean class. But here we also use a action as the body of the action. You must therefore use the complete closing tag () to tell the JSP container where the action ends, instead of the shorthand notation used in Example 5.1. The body of the action is executed only when a new bean is created. In this example, that’s always the case, but as you will learn in Chapter 8, there are cases in which the bean already exists and the action is needed only to associate it with a name. Now let’s take a closer look at the action. As the name implies, this action is used to set the bean’s property values. Like the action, it has a name attribute that must match the id attribute of a action, and a property attribute that specifies which property to set. When a form is submitted, the form field values are sent as request parameters with the same names as the form field elements. In Example 5.3, note that an asterisk (*) is used as the property attribute value of the action. This means that all bean properties with names that match request parameters sent to the page are set automatically. That’s why it’s important that the form element names match the bean property names, as they do here. Automatically setting all matching properties is a great feature; if you define more properties for your bean, you can set them simply by adding new matching fields in the form that invokes the JSP page. Besides the property attribute, the action has two more optional attributes: param and value. If for some reason you can’t use the same name for the parameters and the property names, you can use the param attribute to set a bean property to the value of any request parameter: page 49

Hint: This post is supported by Gama php5 hosting services

Comments are closed.