1
我正在開發一個讀取XML的應用程序,這些XML的值在「對象」(consumerXML)中設置,並且該對象設置在列表中和名單將在會議上進行設置,鍵爲 「結果」Struts:使用邏輯迭代但沒有獲取更新列表值在操作
request.setAttribute("results", list)
流程是這樣的
- 的welcome.jsp它的ActionForm consumerxmlActionForm - >這裏沒有問題
- editxml.jsp即使在這裏,actionform是consumerxmlActio nForm - >這裏列表被填充,但不通過相同的,回來。
editxml.jsp:
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<html:html locale="true">
<head>
<title>Middleware UI</title>
<script language="JavaScript">
function submitFormEdit(frm,cmd) {
frm.operation.value = cmd;
frm.submit();
}
</script>
<html:base />
</head>
<body bgcolor="white">
<html:form action="/consumerxmlActionForm">
<html:hidden property="operation" />
<html:errors />
<table>
<tr>
<td align="center">beanID</td>
<td align="center">dayStartTime</td>
<td align="center">dayEndTime</td>
<td align="center">dayThreshold</td>
<td align="center">nightThreshold</td>
</tr>
<logic:iterate id="consumerXML" name="results" >
<tr>
<td align="center"><html:text name="consumerXML"
property="beanID" /></td>
<td align="center"><html:text name="consumerXML"
property="dayTime" /></td>
<td align="center"><html:text name="consumerXML"
property="nightTime" /></td>
<td align="center"><html:text name="consumerXML"
property="dayThreshold" /></td>
<td align="center"><html:text name="consumerXML"
property="nightThreshold" /></td>
</tr>
</logic:iterate>
<tr>
<td align="right"><html:submit onclick="submitFormEdit(consumerxmlActionForm, 'edit')">Change</html:submit></td>
</tr>
</table>
</html:form>
</body>
</html:html>
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.unicel.vo.ConsumerXML;
import com.unicel.xml.ParseXML;
public class ConsumerXMLAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String operation = request.getParameter("operation");
ConsumerXMLActionForm actionForm = (ConsumerXMLActionForm) form;
if(operation != null && operation.equals("edit")) {
System.out.println("*** Operation is **** " + operation);
System.out.println("*** actionForm.getOtherGWList() ****" + actionForm.getOtherGWList());
System.out.println("*** From Session *** " + request.getAttribute("results"));
if(actionForm.getOtherGWList() != null) {
for(ConsumerXML consumerXML : actionForm.getOtherGWList()) {
System.out.println("*** Current XML *** " + consumerXML);
}
}
} else {
ParseXML parseXML = new ParseXML();
parseXML.parse();
actionForm.setOtherGWList(parseXML.otherGatewayConsumerList);
request.setAttribute("results", parseXML.otherGatewayConsumerList);
}
return mapping.findForward("success");
}
}
import java.util.ArrayList;
import org.apache.struts.action.ActionForm;
import com.unicel.vo.ConsumerXML;
public class ConsumerXMLActionForm extends ActionForm {
private static final long serialVersionUID = 1L;
private ArrayList<ConsumerXML> otherGWList;
private String operation;
private String beanID;
private String dayTime;
private String nightTime;
private String dayThreshold;
private String nightThreshold;
public String getBeanID() {
return beanID;
}
public void setBeanID(String beanID) {
this.beanID = beanID;
}
public String getDayTime() {
return dayTime;
}
public void setDayTime(String dayTime) {
this.dayTime = dayTime;
}
public String getNightTime() {
return nightTime;
}
public void setNightTime(String nightTime) {
this.nightTime = nightTime;
}
public String getDayThreshold() {
return dayThreshold;
}
public void setDayThreshold(String dayThreshold) {
this.dayThreshold = dayThreshold;
}
public String getNightThreshold() {
return nightThreshold;
}
public void setNightThreshold(String nightThreshold) {
this.nightThreshold = nightThreshold;
}
public ArrayList<ConsumerXML> getOtherGWList() {
return otherGWList;
}
public void setOtherGWList(ArrayList<ConsumerXML> otherGWList) {
this.otherGWList = otherGWList;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
}
editxml.jsp正確顯示的列表中,當我點擊 「更改」 按鈕,我不明白的 「結果」在會議中。有沒有其他的方式來獲取該列表?
感謝和問候 Raaghu.K
1)您不是要求會話中的任何內容,而是來自請求 - 我不確定這是問題中的拼寫錯誤還是代碼。 2)無論哪種方式,如果你正在尋找表單值,那些是請求參數,並且應該在動作表單中。你是否說在提交後你沒有看到你期望的形式? –
重新提交表單後是否有問題? – Naved
另外,你不應該使用
Panos