gpt4 book ai didi

java - Struts 1.3 遍历动态问题列表

转载 作者:行者123 更新时间:2023-11-30 09:11:53 27 4
gpt4 key购买 nike

任何帮助将不胜感激:

在我的 JSP 中,我有一个动态问题列表,每个问题都有一个输入字段:

<logic:iterate name="listOfQuestions" id="listOfQuestionsId" indexId="indexId">
<tr>
<td align="right" width="100%"><bean:message key='<%= "prompt.question" + (indexId.intValue() +1)%>'/>:&nbsp;&nbsp;</td><td width="100%" nowrap="nowrap"><bean:write name="listOfQuestionsId"/></td>
</tr>

<tr align="center">
<td align="right" width="50%"><bean:message key="prompt.answer"/>:&nbsp;&nbsp;</td>
<td align="left" width="50%"><html:password property="questions" size="30" maxlength="40" indexed="true"></html:password></td>
</tr>
</logic:iterate>

问题和答案字段显示正常。

我唯一的问题是试图访问我的操作类中所有输入字段的值。

这是我的表格:MultipleQuestionsForm

public class MultipleQuestionsForm extends ActionForm {

private List<String> questions=null;

/**
* @return the questions
*/
public List<String> getQuestions() {
return questions;
}


/**
* @param questions the questions to set
*/
public void setQuestions(List<String> questions) {
this.questions = questions;
}

//omitted the rest (Validate, constructor, reset method)
}

这是我的 ActionClass 的一部分:

getQuestions() 返回 null

//Use the ValidateInfoForm to get the request parameters
MultipleQuestionsForm validateQuestionsForm = (MultipleQuestionsForm) form;
List<String> listOfquestions = validateQuestionsForm.getQuestions();

for(String s: listOfquestions) System.out.println(s); //nullPointer since getQuestions() doesn't return the input values

最佳答案

您如何期望您的问题属性呈现为 List<String> questions从你的 jsp/ View ?你试过调试你的validateQuestionsForm吗? ?如果是这样,请检查您的问题属性。您需要做的就是将列表属性更改为 String array .在您的 MultipleQuestionsForm 中这样,

private String[] questions;

以及此属性的 getter setter。现在您可以接收字符串数组并对其进行迭代。希望这会有所帮助。

关于java - Struts 1.3 遍历动态问题列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21888084/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com