Java Reference
In-Depth Information
The following source code should be in the class:
package c11;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
public class TNTStateDDM extends TagSupport {
private String selected = "FL";
public String getSelected() {
return selected;
}
public void setSelected(String selected) {
this .selected = selected;
}
public int doStartTag() throws JspException {
return super .doStartTag();
}
}
9.
In doStartTag, before the return statement, add the following two statements to define the
drop-down menu (make sure there is a blank line between them):
pageContext.getOut().write("<SELECT name=\"stateDDM\">");
pageContext.getOut().write("</SELECT>");
These statements will be flagged as errors because the write method can throw an exception. We will have RAD
generate the appropriate try / catch ..
10. Select the statements and click Source, Surround With, and then Try/catch Block.
The try / catch statements will be added and the statements will no longer be flagged as errors.
Arrays
Before we go any further, we have to cover a topic that should have been covered much earlier: arrays. An array is a
“structure” that can hold many primitive values or many reference variables of the same type. In other words, an array
could be defined to hold multiple int values or multiple String variables. However, an array cannot be defined to
hold both int values and String variables. Another way to say this is that arrays are typed . When the array is defined,
the type of values it will hold must be specified. So for example, the following would define an array object that can
hold seven int values:
new int[7];
Of course, this new array of integers can't be accessed because it was assigned to a variable. To use this array, an
integer array variable (e.g., myFirstArray) must be defined and the array assigned to it as follows:
int [] myFirstArray = new int [7];
Great, we have achieved array! Maybe we should put something into the array? To reference a particular array
“bucket,” simply specify the bucket's index/position number and assign a value using the equal sign. For instance, the
following would assign the value 42 to the fifth bucket:
myFirstArray[4] = 42;
 
Search WWH ::




Custom Search