Я занимаюсь разработкой приложения, которое читает XML. Значения этих XML установлены в «Object» (consumerXML), и этот объект установлен в списке, а список будет установлен в сеансе, ключ - «результаты»
request.setAttribute("results", list)
Поток такой
- Welcome.JSP, форма действия которого - consumerxmlActionForm -> Здесь нет проблем
- editxml.jsp Даже здесь actionform - consumerxmlActionForm -> здесь список заполняется, но не передает то же самое, обратно.
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