gpt4 book ai didi

java - 表单没有提交选中的

转载 作者:行者123 更新时间:2023-11-30 07:18:44 25 4
gpt4 key购买 nike

我有以下下拉列表,它正确显示了选项但是当我选择一个项目并提交表单时它遇到了以下错误:

'select', field 'list', name 'name': The requested list key 'listnames' could not be 
resolved as a collection/array/map/enumeration/iterator type. Example: people or
people.{name} - [unknown location]

我的 JSP 表单

      <s:form method="POST" action="addNames">
<s:select name="name"
label="Names"
list="listnames"
/>
</s:form>

我的行动

 @Action
public class Myaction implements ModelDriven{
private MyClass myclass = new MyClass();
private List listnames = new ArrayList();

@Override
public MyClass getModel() {
return this.myclass;
}

public List getListnames() {
return listnames;
}

public void setListnames(List listnames) {
this.listnames = listnames;
}


public MyClass getMyClass() {
return myclass;
}

public void setMyClass(MyClass myclass) {
this.myClass = myclass;
}
}

我的类(class)

 public class MyClass {
private String name;

..... getter and setters go here ....
}

支柱

<package name="MyUsers" extends="default" namespace="/MyUsers">
<action name="*" method="{1}" class="com.myproject.controller.Myaction">
<result name="uAdd" type="tiles" >uAdd</result>
<result name="uView" type="tiles" >uView</result>
</action>
</package>

最佳答案

第 1 步:确保正确完成 listnames 的 getter 和 setter

第 2 步:确保您已正确完成 listnames List 的声明和初始化

更新 2示例示例

struts.xml

<action name="getText" class="commonpackage.ReportsCommonClass" method="getText">
<result name="success">index.jsp</result>
</action>

<action name="myaction" class="commonpackage.ReportsCommonClass" method="myaction">
<result name="success">index2.jsp</result>
</action>

index.jsp

 <s:form id="conform" action="myaction" method="post">
<label>NAME</label>
<s:select id="name1" name="name1" list="mylist" headerKey="0" headerValue="--SELECT--"/>

<s:submit value="Click" />
</s:form>

在 commonpackage.ReportsCommonClass 类中

ArrayList mylist=new ArrayList();

public ArrayList getMylist() {
return mylist;
}

public void setMylist(ArrayList mylist) {
this.mylist = mylist;
}

public String getText()
{
mylist.add("NAME 1");
mylist.add("NAME 2");
mylist.add("NAME 3");
mylist.add("NAME 4");
mylist.add("NAME 5");
return SUCCESS;
}
String name1;

public String getName1() {
return name1;
}

public void setName1(String name1) {
this.name1 = name1;
}


public String myaction()
{
System.out.println("NAMEEEEEEEEEEEEEEEEEEEEE:"+name1);
return SUCCESS;
}

关于java - 表单没有提交选中的<s :select>值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15150706/

25 4 0