• Post Reply Bookmark Topic Watch Topic
  • New Topic

servlet Map help  RSS feed

 
Scott
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been a while since I have written any code and I am having an issue getting back into it.

I am currently working on creating servlet to pass info from all my forms to my business logic. However, I am having an issue with getting the data. This may be a topic for a different forum, but I figured I would ask here.

I tested out the servlet with the getParameter() method, and I can get the values. However, when I try to use the java.util.Map, I get blank values.

I think the issue may be that I forgot how to use the Map object. Here is my code:

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet CalCartController</title>");
out.println("</head>");
out.println("<body>");

for (int i = 0; i < formParamsMap.size(); i++) {
Map.Entry entry = (Map.Entry) keyValuePairs.next();
String key = (String)entry.getKey();
String value = (String)entry.getValue();

out.println(value);
}

out.println("<h1>Servlet CalCartController </h1>");
out.println("</body>");
out.println("</html>");
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37250
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott,

We're pleased to have you here with us here at JavaRanch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character.

Thanks,
Jeanne
Forum Sheriff
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not directly iterate over map. however you can iterate over the set of Map.entry.

Example
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!