开发者社区> 问答> 正文

request.getParameterValues()问题?报错

在一个JSP页面中,多个<input>的name一样,在servlet中用Map<Integer,String[]> map = new HashMap<Integer, String[]>();
map.put(id, request.getParameterValues(idStr));//这里的idStr就是
                                                //<input> 的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]);
}
/
}

会报错?

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)

展开
收起
爱吃鱼的程序员 2020-06-22 17:17:41 751 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    直接map.get(id)不就拿出来string[]数组了吗然后再遍历数组。map.get(i).length这边报空指针了,map.get(i)取出来的是空的。另外这样迭代map不对的。map.get(key)中的参数是代表key值,而不应该是你现在这个迭代里面的变量值。恩!你说的很对!那应该怎样写呢?Map<Integer,String[]>map=newHashMap<Integer,String[]>();
    for(Entry<Integer,String[]>entry:map.entrySet()){
     System.out.println(entry.getKey());

      System.out.println(entry.getValue());

      这这里判断一下entry.getValue()的值,然后循环,注意空校验

    }

    2020-06-22 17:17:56
    赞同 1 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载