1

.jsp

 <c:forEach items = "${allContacts}" var="contact">
            <c:out value="${contact.firstName}"/>,
            <c:out value="${contact.lastName}"/>
     </c:forEach>

ContactService.java

  public static List listContacts() {
        return toList(contacts);

    }

    private static List toList(Map contacts) {
        List contactList = new ArrayList();
        Iterator iterator = contacts.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Contact contact = (Contact) entry.getValue();
            contactList.add(contact);
        }
        return contactList;
    }

ListContactsController.java

public class ListContactsController extends AbstractController {

    public ListContactsController() {
    }

    public ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        List allContacts = ContactService.listContacts();

        return new ModelAndView("ListContacts","allContacts", allContacts);
    }
}

I am trying to list allContacts, but is only shows "," as output. The data shows in GET but does not display in the webpage. What is the problem?

2
  • 1
    could you please post the Class of the object you put into the allContacts list. Commented Oct 2, 2012 at 9:32
  • I mean the objects in the list returned by ContactService.listContacts()! Commented Oct 2, 2012 at 10:32

1 Answer 1

2

You might not have added your allContacts object in your controller:

session.setAttribute("allContacts", allContactsVariable);

@Ralph's comment:

Since a comma is printed out, it means that there are objects existing in your list but the objects do not have values in their fields.

Have you tried adding the values after your GET? E.g., contact1.setFirstName("value"); OR contact.setLastName("value")

Sign up to request clarification or add additional context in comments.

3 Comments

This can not be the problem, because if the collection allContracts is empty or null then there would be no , in the output!
you should not be using session with spring MVC unless it is needed. in spring MVC, you should add your object/variable to the model.
Where i want to do this change

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.