木叶下521
2013-08-22 16:48
浏览 883
已采纳

request.getParameterValues()问题

在一个JSP页面中,多个的name一样,在servlet中用Map map = new HashMap();
map.put(id, request.getParameterValues(idStr));//这里的idStr就是
// 的name
为什么
for(int i=0;i<map.size();i++){
System.out.println(map.size());
System.out.println(map.get(i).length);
/*for(int j=0;j<str.length;j++){
System.out.println(str[j]);
}*/
}
会报错?
[code="java"]2013-8-22 16:33:41 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet AddAnswerSheetServlet threw exception
java.lang.NullPointerException
at com.answerSheetServlet.AddAnswerSheetServlet.doPost(AddAnswerSheetServlet.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.util.ChinaFilter.doFilter(ChinaFilter.java:16)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
at java.lang.Thread.run(Thread.java:619)[/code]

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dashabenmao 2013-08-22 16:56
    已采纳

    String langtype[]=request.getParameterValues("idStr");

    for (int i=0;i<size;i++)
    {
    out.println(langtype[i]+"");
    }

    上面是循环输出

    你for 循环 map 要这么写。
    Map map = new LinkedHashMap();
    map.put(1, "星期一");
    map.put(2, "星期二");
    map.put(3, "星期三");
    map.put(4, "星期四");
    map.put(5, "星期五");
    map.put(6, "星期六");
    map.put(7, "星期日");

    for(Map.Entry entry: map.entrySet()) {
    System.out.print(entry.getKey() + ":" + entry.getValue() + "\t");
    }

    点赞 打赏 评论
  • xblueskyleng 2013-08-22 17:12

    map.put(key,value);
    value=map.get(key);

    map.put(id, request.getParameterValues(idStr));
    for(int i=0;i<map.size();i++){
    System.out.println(map.size());
    System.out.println(map.get(i).length);
    }

    你上面的id=0吗?不然的话map.get(i)也就是map.get(0)是null,null也就不能length。List才是get(0),get(1)这样

    点赞 打赏 评论

相关推荐 更多相似问题