Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用spring在J2ee中将数据从控制器传递到视图_Java_Spring_Jsp - Fatal编程技术网

Java 如何使用spring在J2ee中将数据从控制器传递到视图

Java 如何使用spring在J2ee中将数据从控制器传递到视图,java,spring,jsp,Java,Spring,Jsp,我有一个带有SpringMVC的简单J2ee应用程序。现在我想从jsp页面调用一个方法到他的控制器,我想从控制器获得一个信息。因此,我编写了以下代码: registrazione.jsp: <script language="javascript"> function saveRigaTable2(){ try{ var nome = document.getElementById("nome").value;

我有一个带有SpringMVC的简单J2ee应用程序。现在我想从jsp页面调用一个方法到他的控制器,我想从控制器获得一个信息。因此,我编写了以下代码:

registrazione.jsp:

<script language="javascript">  

    function saveRigaTable2(){

        try{
            var nome = document.getElementById("nome").value;
            var ajaxHandler = new AjaxHandler('POST', '<c:url value="${pageName}"/>.html', false);   
            ajaxHandler.encodeParameter('method', 'saveItems');
            ajaxHandler.encodeParameter('nome', nome);

            ajaxHandler.callbackHandler = function()
            {           
                if (ajaxHandler.getRequest().readyState == 4)
                {   
                    if (ajaxHandler.getRequest().status == 200)
                    {
                        var xmlDoc = ajaxHandler.getRequest().responseXML;

                        var itemsException = xmlDoc.getElementsByTagName("exception");
                        alert(itemsException.length);
                        var items = xmlDoc.getElementsByTagName("registrazioneOK");
                        alert(items.length);
                        if (itemsException.length!=0)
                        {
                            var punto=itemsException[0];
                            alert(punto.getAttribute("text"));
                            document.getElementById("error").innerHTML=punto.getAttribute("text");
                            alert('Impossibile1 eseguire l\' operazione');
                        }
                        if (items.length!=0)
                        {
                            var punto=items[0];
                            alert(punto.getAttribute("text"));
                        }
                    }
                }
            };

            ajaxHandler.startRequest();   
        }
        catch (e)
        {
            alert('Impossibile eseguire l\' operazione');
        }      
    }
</script>
这是ajax_callback.jsp

<%@ page contentType="text/xml"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<?xml version="1.0" encoding="iso-8859-1"?>
<dataSet>
   <c:forEach var="dataItem" items="${dataSet}">
        <<c:out value="${dataItem.tagName}"/> 
        <c:forEach var="attribute" items="${dataItem.attributes}">
            <c:out value="${attribute.id}"/>="<c:out value='${attribute.description}'/>" 
        </c:forEach>/>
    </c:forEach>
</dataSet>

当我运行此代码时,我无法读取信息,项目的长度始终为0。 我的错误在哪里

编辑:这是我从ajax_callback.jsp获得的xml的休息:

<?xml version="1.0" encoding="UTF-8"?>
<dataSet>
        <
            exception 

                    text="Complimenti. Registrazione avvenuta con successo."        
        />

<
例外情况
text=“恭维。注册成功。”
/>
这就是xml的错误

Errore interpretazione XML: la dichiarazione XML o testuale non è all’inizio di un’entità Indirizzo: moz-nullprincipal:{d84efa50-0bb7-4f19-b93a-de7ebc15f366} Riga numero 3, colonna 1:

<?xml version="1.0" encoding="UTF-8"?>
^
错误解释XML:la dichiarazione XML o testuale nonèall'inizio di un'entitèIndirizzo:moz nullprincipal:{d84efa50-0bb7-4f19-b93a-de7ebc15f366}数字3,柱廊1:
^

我想错误出在ajax_callback.jsp上,我已经在这个模式下修复了这个问题(使用这段代码)

<%@ page contentType="text/xml"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<?xml version="1.0" encoding="iso-8859-1"?>
<dataSet>
   <c:forEach var="dataItem" items="${dataSet}">
        <<c:out value="${dataItem.tagName}"/> 
        <c:forEach var="attribute" items="${dataItem.attributes}">
            <c:out value="${attribute.id}"/>="<c:out value='${attribute.description}'/>" 
        </c:forEach>/>
    </c:forEach>
</dataSet>


我已经移动了
“好的,因为我认为我已经从jsp的保留版本获得了代码。但是,我怎样才能修复它呢?好的,我知道,当我尝试插入一个用户建议我的代码时,我出现了这个错误,然后他删除了你的答案。现在我用原始代码替换了他的代码,我没有任何错误,但是元素的长度始终为0。还有一个问题,这段代码被弃用了?问题是如何将模型从控制器读取到JSP?
<?xml version="1.0" encoding="UTF-8"?>
<%@ page contentType="text/xml"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<dataSet>
   <c:forEach var="dataItem" items="${dataSet}">
        <<c:out value="${dataItem.tagName}"/> 
        <c:forEach var="attribute" items="${dataItem.attributes}">
            <c:out value="${attribute.id}"/>="<c:out value='${attribute.description}'/>" 
        </c:forEach>/>
    </c:forEach>
</dataSet>