首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Struts :使用但不获取操作中的更新列表值

Struts :使用但不获取操作中的更新列表值
EN

Stack Overflow用户
提问于 2011-09-02 11:34:43
回答 1查看 2.3K关注 0票数 1

我正在开发一个读取XML的应用程序,这些XML的值是在" object“(consumerXML)中设置的,该对象是在列表中设置的,列表将在会话中设置,关键是”结果“。

代码语言:javascript
复制
request.setAttribute("results", list)  

水流是这样的

here

  • editxml.jsp
  1. Welcome.JSP,它的操作形式是consumerxmlActionForm -> No,即使在这里,actionform是consumerxmlActionForm ->这里列表被填充,但是没有传递相同的.

editxml.jsp:

代码语言:javascript
复制
<%@ 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>

代码语言:javascript
复制
 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正确地显示列表,当我点击“更改”按钮时,我无法在会话中获得“结果”。还有别的方法去取名单吗??

谢谢,并向拉古夫问好。

EN

回答 1

Stack Overflow用户

发布于 2014-04-23 19:53:33

您应该使用表单将值返回到操作中,并使用id并在那里给VO。然后形式将在行动中可用。你不需要这个会话。

代码语言:javascript
复制
        <logic:iterate name="monthlyGainLossForm" property="ptcList" id="productTaxCat">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7282812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档