在MVC中,将列表从JSP传递到控制器 [英] In MVC passing a list from JSP to the Controller

查看:59
本文介绍了在MVC中,将列表从JSP传递到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个将列表从JSP传递到Controller以便工作的示例:

I'm trying to get an example of passing a list from JSP to the Controller to work:

http://viralpatel.net/blogs/spring -mvc-multi-row-submit-java-list/

这个示例的问题是我没有使JSP/WebContent/WEB-INF/jsp/add_contact.jsp正常工作.他有一行:

the problem I have with this example is that I do not get the JSP /WebContent/WEB-INF/jsp/add_contact.jsp to work. He has the line:

<c:foreach items="${contactForm.contacts}" var="contact" varstatus="status">

并且 varstatus 变量出现错误.他从哪里获得该变量的值?他将其用作列表行索引,但值应从何而来?我在日食中收到警告,它是一个未定义的变量varstatus,如果我仍将其部署到tomcat,则会收到以下错误:jstl foreach标记不支持多个变量(因为我已经在那儿有联系了). /p>

and i'm getting errors with the varstatus variable. From where is he getting the values for this variable? He is using it as a list row index, but from where should the values come? I get the warning in eclipse that it is a not defined variable varstatus and if i still deploy it to tomcat, then i get the error that jstl foreach tag does not support more than one variable (as i already have the contact there).

推荐答案

The forEach tag and attributes are case sensitive.

<c:forEach items="${contactForm.contacts}" var="contact" varStatus="status">
    <c:out value="${status.index}" />: <c:out value="${contact}" />
</c:forEach>

Eclipse生成的错误消息可能会误导您.错误也可能是页面上的其他地方引起的.如果这样做不能解决问题,请发布完整的JSP和stacktrace以更好地理解.

It's possible the error messages generated by Eclipse are misleading. It's also possible the error is originating from somewhere else on the page. If this does not resolve the problem, post the full JSP and stacktrace for better understanding.

这篇关于在MVC中,将列表从JSP传递到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆