Java Reference
In-Depth Information
Review Exercise
The Web page ShipInfoForm does not display the current date and time. So, in this exercise you will create a JSP called
EnterShipInfoJSP with this information to replace the static Web page. The new date and time components will be
implemented as beans. Each date and time bean will simply return HTML (as a string) to define a drop down menu
with the appropriate value selected. For example, if MonthBean is accessed in April, it will return the following HTML
that defines a drop-down menu with the values 1 through 12, and 4 as the selected value.
<SELECT name='MonthDDM'>
<OPTION value='1'>1</OPTION>
<OPTION value='2'>2</OPTION>
<OPTION value='3'>3</OPTION>
<OPTION value='4' selected>4</OPTION>
<OPTION value='5'>5</OPTION>
<OPTION value='6'>6</OPTION>
<OPTION value='7'>7</OPTION>
<OPTION value='8'>8</OPTION>
<OPTION value='9'>9</OPTION>
<OPTION value='10'>10</OPTION>
<OPTION value='11'>11</OPTION>
<OPTION value='12'>12</OPTION>
</SELECT>
EnterShipInfoJSP will use tags to access the various beans.
1.
In ReviewExWeb/Java Resources/src, create a new folder called c9.
2.
In ReviewExWeb/ Java Resources/src/c9, create a new Java class called MonthBean.
3.
Replace the MonthBean default source code with the following:
package c9;
import java.util.Calendar;
public class MonthBean {
public String monthDDM = new String();
private int currMonth;
private Calendar c = Calendar.getInstance();
public MonthBean() {
}
public String getMonthDDM() {
currMonth = c.get(Calendar.MONTH) + 1;
StringBuffer monthDDM =
new StringBuffer("<SELECT name='MonthDDM'>");
for ( int ctr = 1; ctr <= 12; ctr++) {
monthDDM.append("<OPTION value='");
monthDDM.append(String.valueOf(ctr));
if (ctr == currMonth) {
monthDDM.append("' selected>");
} else {
monthDDM.append("'>");
}
 
Search WWH ::




Custom Search