我有一个List<String>
在我的ActionForm
必须使用 Struts1.1
将其表示为 JSP 页面中的文本字段
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>
因为属性可以指向特定变量并且 List<SomeClass>
充当一个 bean。
<logic:iterate id="listUserId" property="listUsers" name="pForm">
<html:text name="listUserId" property="username"/>
</logic:iterate>
其中 listUsers 是 List
与 User
类(class)类型
私有(private)列表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;
}
}
最佳答案
检查struts-logic-iterate-example 。您的代码应为 -
<logic:iterate id="urlIterate" name="pForm" >
<html:text property="urlIterate" indexed="true"/>
</logic:iterate>
关于java - 如何显示html :text using <logic:iterate> for List<String> in Struts1. 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28690623/