1. Concept introduction
The use of html tags in stust1, including html:select, html:option, details are as follows
<html:select property="test String " size="1"> <html:option value="value1">Show Value1</html:option> <html:option value="value2">Show Value2</html:option> <html:option value="value3">Show Value3</html:option> <:html:submit property="submit" value="提交"/> </html:select>
Among them, property represents the corresponding property name in the selection list and ActionForm. When the user clicks submit, the value of the option selected by the user will be seen on the test page. The following is the running effect of the code:
Show Value1 Show Value2 Show Value3
The following is an example of multiple="true" and size="8"
value1 value2 value3 value4 value5 value6 value7 value8 value9 value10
When the multiple attribute is true, in The corresponding property in ActionForm should be an arraytype so that multiple values selected by the user can be assigned to it at the same time.
<html:select property="testString" size="1"> <html:option value="value1">Show Value1</html:option> <html:option value="value2">Show Value2</html:option> <html:option value="value3">Show Value3</html:option> </html:select>
An option has two important parts. The first is the content it displays to the user, which can be specified in the following way:
<html:option value="value1">Show Value1</html:option>
As can be seen, the part between two
Another important content is the value it passes to ActionForm. This is specified by the tag's value attribute. As in the above example, the values of value are value1, value2 and value3 respectively. When the user selects a certain tag, the JSP page will pass the value corresponding to the tag to the corresponding attribute in the ActionForm.
The following is the running effect:
Show Value1 Show Value2 Show Value3
2. Secrets that cannot be told
<html:option></html:option>转化成<option></option>时加了selected属性,RTFSC,看源码 if(selectTag().isMatched(value)) results.append(" selected=\"selected\""); public boolean isMatched(String value) { /* <-MISALIGNED-> */ /* 126*/ if(match == null || value == null) /* <-MISALIGNED-> */ /* 127*/ return false; /* <-MISALIGNED-> */ /* 130*/ for(int i = 0; i < match.length; i++) /* <-MISALIGNED-> */ /* 131*/ if(value.equals(match[i])) /* <-MISALIGNED-> */ /* 132*/ return true; /* <-MISALIGNED-> */ /* 135*/ return false; } if(value != null) {/* 234*/ match = new String[1]; /* 235*/ match[0] = value; } else { /* 238*/ Object bean = TagUtils.getInstance().lookup(super.pageContext, name, null); /* 239*/ if(bean == null) {/* 240*/ JspException e = new JspException(messages.getMessage("getter.bean", name)); /* 243*/ TagUtils.getInstance().saveException(super.pageContext, e); /* 244*/ throw e; } /* 248*/ try { /* <-MISALIGNED-> */ /* 248*/ match = BeanUtils.getArrayProperty(bean, property); //获取form中的select的value值 /* <-MISALIGNED-> */ /* 249*/ if(match == null) /* <-MISALIGNED-> */ /* 250*/ match = new String[0]; } /* 254*/ catch(IllegalAccessException e) { /* <-MISALIGNED-> */ /* 254*/ TagUtils.getInstance().saveException(super.pageContext, e); /* <-MISALIGNED-> */ /* 255*/ throw new JspException(messages.getMessage("getter.access", property, name)); }
3. Unsolved problems, how to set the default selection using html:option, there is no selected attribute
The above is the detailed content of Detailed explanation of the selected attribute when converting