Struts:使用逻辑迭代但未在操作中获取更新的列表值
我正在开发一个读取 XML 的应用程序,这些 XML 的值设置在“对象”(consumerXML)中,该对象设置在列表中,列表将设置在会话中,密钥是“结果”,
request.setAttribute("results", list)
流程就像这个
- Welcome.JSP,其actionform 是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 正确显示列表,当我单击“更改”按钮时,我在会话中没有得到“结果”。还有其他方法可以获取该列表吗?
感谢和问候 拉古·K
I am developing a application which reads a XML , The values of these XML are set in a "Object" (consumerXML) and that object is set in a list and list will be set in session , Key being "results"
request.setAttribute("results", list)
The Flow is like this
- Welcome.JSP whose actionform is consumerxmlActionForm --> No Issues here
- editxml.jsp Even here the actionform is consumerxmlActionForm --> here list gets populated but doesnt pass the same, back.
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 displays the list properly, when I click on the "change" button I dont get the "results" in session. Is there any other way to fetch that list??
Thanks and Regards
Raaghu.K
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用表单将值返回到操作并使用 id 并在那里给出 VO。然后表格就可以使用了。您不需要为此进行会话。
You should use the form to get values back to action and use the id and give VO there. Then Form will be available in action. You dont need session for this.