Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to call Java method which returns me the array list and I want to add that array list to the drop-down list in JSP. When user select one value from the drop-down list that value is stored in the variable type

<form action="Config.action" method="post">
<table width="600" height="34" align="center" border="1" bgcolor="#CCCCCC"><br>
<%     
    Config c = new Config();
    ArrayList<String> names = c.populate();
    out.print("<table>  <tr><select>");

    for (String s : names) 
    {
        out.print("<option value="+s+">"+s+"</option>");
    }    
%>    
</select></table>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
200 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use action properties to get/set the names

private String name;
//getter and setter

public ArrayList<String> getNames(){
  Config c = new Config();
  return c.populate();
}

JSP:

<form action="Config.action" method="post">
<table width="600" height="34" align="center" border="1" bgcolor="#CCCCCC"><br>
<s:select name="name" list="names"/>
</table>
</form>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...