Home>

A small problem encountered in the project,In conclusion.

On the use of struts2 select tags.

Struts2 traverses data from other tables, populates the drop-down menu and displays it with thetag.

struts2 version is 2.1.8

<s:select

list=""

name=""

value=""

headerkey=""

headervalue=""

listkey=""

listvalue=""

/>

(1) where list is a required attribute list can store map list set data

list attribute:usually defined in action,Must be an iterable source,Such as a list, map, set, etc. If it is a map, then the key of the map corresponds to the value in the select tag, and the value in the map corresponds to the option in the select tag. If it is a list or a set, it can be specified by listkey and listvalue.

(2) If list is empty, headkey and headvalue cannot be empty.listkey and listvalue:listkey corresponds to the value in the select tag, and listvalue corresponds to the option in the select tag

(3) the name attribute:the name of the selection in the form.

The meaning of each attribute is explained in detail below.

headervalue:default value

headerkey:default name

list:source data (you can get the list from the database in the action method)

name:The location where the selected data is stored (here, we need to define the object in the action in the attribute value username of the object obj)

listkey:name of the drop-down option

listvalue:value of the drop-down option

value:default value

1. The first example:

<s:select list="{" aa "," bb "," cc "}" theme="simple" headerkey="00" headervalue="00"></s:select>

2. The second example:

<s:select list="#{1:" aa ", 2:" bb ", 3:" cc "}" label="abc" listkey="key" listvalue="value" headerkey="0" headervalue="aabb">

3. The third example:

<%
java.util.hashmap map=new java.util.linkedhashmap ();
map.put (1, "aaa");
map.put (2, "bbb");
map.put (3, "ccc");
request.setattribute ("map", map);
request.setattribute ("aa", "2");
%>
<s:select list="#request.map" label="abc" listkey="key" listvalue="value"
 value="#request.aa" headerkey="0" headervalue="aabb"></
s:select
>

headerkey headervalue set the default value

4. Fourth example

public class program implements serializable {
  /** serialversionuid * /
  private static final long serialversionuid=1l;
  private int programid;
  private string programname;
  public int getprogramid () {
    return programid;
  }
  public void setprogramid (int programid) {
    this.programid=programid;
  }
    public string getprogramname () {
    return programname;
  }
  public void setprogramname (string programname) {
    this.programname=programname;
  }
}
 xxxextends extends actionsupport {
  private list<program>programs;
    public list<program>getprograms () {
    return programs;
  }
  public void setprograms (list<program>programs) {
      this.programs=programs;
  }
}

On jsp page

<s:select list="programs" listvalue="programname" listkey="programid" name="program"
headerkey="0l" headervalue="" value="bean.programid"></s:select>

Where:list="programs" is the list in the action, and listvalue="programname" is thecorresponding to the field programname in the bean

listkey="programid" is

jsp
  • Previous Judging spider code black hat jump code according to user-agent (js version and php version)
  • Next Step by step to teach you to create a table partition of the SQL database