为列表
List<String>
我
ActionForm
其具有使用被表示为在JSP页面中的文本字段
Struts1.1
List<String> url=new ArrayList<String>();
public List<String> getUrl() {
return url;
}
public void setUrl(List<String> url) {
this.url = url;
}
以下是我已经JSP页面内使用
<logic:iterate id="urlIterate" name="pForm" property="url">
<html:text property="?????" name="urlIterate"/>
</logic:iterate>
<html:text>
工作好List<SomeClass>
因为属性可以是指向特定的变量和代码充当豆。
<logic:iterate id="listUserId" property="listUsers" name="pForm">
<html:text name="listUserId" property="username"/>
</logic:iterate>
其中listUsers是List
与User
型类 私人列表listUsers的; 在property="username"
username
里面User
类
一个变量List<String>
<bean:write name="urlIterate" />
我没有发现问题,显示为使用<bean:write>
,因为它只有name
属性的文本。 但要使用<html:text>
,我们需要添加另一个强制属性property
。
任何人都可以帮助我。 property='?????'
为了使html:text
正常工作,需要使用什么值。
在此先感谢
提供了更多的代码.. 的UI JSP页面。
<%@taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<html>
<head>
</head>
<body>
<html:form action="/plist">
<h1>Struts <logic:iterate> example</h1>
<logic:iterate property="listMsg" name="pForm" id="listMsgId">
<p>
List Messages </p> <html:text property="listMsgId" indexed="true"/>
</logic:iterate>
<html:submit/>
</html:form>
</body>
</html>
Action类:
public class PrintMsgAction extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception {
List<OptionsListCollection> listoptions=new ArrayList<OptionsListCollection>();
for(int i=0;i<10;i++){
listoptions.add(new OptionsListCollection("Option"+i, "OptionValue"+i));
}
List<String> listMsg = new ArrayList<String>();
listMsg.add("Message A");
listMsg.add("Message B");
listMsg.add("Message C");
listMsg.add("Message D");
PrintForm pForm=(PrintForm)form;
pForm.setListMsg(listMsg);
return mapping.findForward("plist");
}
}
和ActionForm
public class PrintForm extends ActionForm{
private List<String> listMsg;
public List<String> getListMsg() {
return listMsg;
}
public void setListMsg(List<String> listMsg) {
this.listMsg = new ArrayList<String>();
this.listMsg = listMsg;
}
}
嗨法雷尔,我一直在使用'属性=“URL”'尝试之前,就有了一个例外,'javax.servlet.ServletException:javax.servlet.jsp.JspException:没有找到getter方法bean urlIterate的属性url。您指定的链接是关于“”而不是“”。 –
2015-02-24 09:34:29
现在我已经通过在我的代码的中删除了'property =“url”'来尝试你的代码,并且仍然收到一个异常。 'javax.servlet.ServletException:javax.servlet.jsp.JspException:无法为此集合创建迭代器' –
2015-02-24 09:42:30
您可以添加表单吗? – farrellmr 2015-02-24 09:45:56