在实现简单的本地登录系统时,需要把page1.jsp的表单显示在page2.jsp中。

其中获取page1.jsp表单的办法就是在页面1的<form>中加入action="page2.jsp"

like this:

<form name="users_name" action="page2.jsp">
<p>
<label>Name</label>
<input type="text" name="name">
</p>
<p>
<label>Gender</label>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
</p> <p>
<label>Interest</label>
<input type="checkbox" name="interest" value="Sing">Sing
<input type="checkbox" name="interest" value="Dance">Dance
<input type="checkbox" name="interest" value="Play balls">Play balls
<input type="checkbox" name="interest" value="Play games">Play games
</p>
<p id="buttons">
<input type="submit" value="Submit">
</p>

前两种轻松用request.getParameter()解决

    Name:<%=request.getParameter("name")%><br>
Sex:<%=request.getParameter("gender")%><br>

而在获取checkbox 时用request.getParameterValues()却出现了问题

Habits:<%= request.getParameterValues("interest")%><br>

输出时输出了:Habits:[Ljava.lang.String;@5f0df6e9

在网上搜索后发现:getParamerterValues()为获取数组的方法

getParamerterValues与request.getParameter的区别:    https://blog.csdn.net/moreorless/article/details/4199677

然后改成for循环输出:

Habits:<%
String[] habits = request.getParameterValues("interest");
for( int i = 0; i<habits.length; i++)
System.out.println(habits[i]);
%><br>

结果被抛出异常:


Type Exception Report

Message An exception occurred processing JSP page /printinfo.jsp at line 20

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /printinfo.jsp at line 20

17:     Sex:<%=request.getParameter("gender")%><br>
18: Habits:<%
19: String[] habits = request.getParameterValues("interest");
20: for( int i = 0; i<habits.length; i++)
21: System.out.println(habits[i]);
22: %><br>
23: </body> Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:613)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Root Cause

java.lang.NullPointerException
org.apache.jsp.printinfo_jsp._jspService(printinfo_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:472)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Note The full stack trace of the root cause is available in the server logs.


脑瓜疼。。

说明

habits根本就没收到来自request.getParameterValues("interest")传值
经过多番查找,找到了问题所在
Habits:<%
String[] habits = request.getParameterValues("interest");
if(habits!=null)
{
for(int i=0;i<habits.length;i++)
{
out.print(habits[i]);
}
}
%><br>

原来犯了个非常低级的错误,在获取值的时候没有判断来的值是否为空。。。。

以后千万长记性嗷!!

request.getParameterValues 出现 [Ljava.lang.String;@ 错误的更多相关文章

  1. Java中调用c/c++语言出现Exception in thread "main" java.lang.UnsatisfiedLinkError: Test.testPrint(Ljava/lang/String;)V...错误

    错误: Exception in thread "main" java.lang.UnsatisfiedLinkError: Test.testPrint(Ljava/lang/S ...

  2. com.opensymphony.xwork2.ognl.OgnlValueStack] - target is null for setProperty(null, "emailTypeNo", [Ljava.lang.String;@6f205e]

    情况1,查询结果未转换为与前台交互的实体类DTO 实体类:EmailTypeDto package com.manage.email.dto; public class EmailTypeDto { ...

  3. ognl.OgnlException: target is null for setProperty(null, "emailTypeNo", [Ljava.lang.String;@1513fd0)

    [com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting expression 'emaiTypeDto.emailTypeNo' w ...

  4. 疑难杂症:java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.setXmlVersion(Ljava/lang/String;)V

    错误: java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.setXmlVersion(Ljava/lang/Strin ...

  5. Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.codec.digest.DigestUtils.sha1Hex(Ljava/lang/String;)Ljava/lang/String;

    异常:Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.co ...

  6. SpringBoot报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

    错误:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String ...

  7. Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z

    1.window操作系统的eclipse运行wordcount程序出现如下所示的错误: Exception in thread "main" java.lang.Unsatisfi ...

  8. org.apache.xerces.dom.ElementNSImpl.setUserData(Ljava/lang/String;Ljava/lang

    HTTP Status 500 - Handler processing failed; nested exception is java.lang.AbstractMethodError: org. ...

  9. windows 运行hadoop的WordCount报nativeio.NativeIO$Windows.createDirectoryWithMode0(Ljava/lang/String;I)

    window eclipse连接hadoop集群,本地运行wordcount,报以下错误,尝试网络上的方法无果,如:换64JDK,添加hadoop_home,path,以及在hadoop\bin和c: ...

随机推荐

  1. Microsoft Store应用安装路径和应用推荐——如何用Linux命令操控windows

    本人是cnblog萌新,刚学编程不久的菜鸟,这是我的第一篇博客,请各位轻喷 Microsoft store安装路径: 相信很多人都跟我一样有强迫症,文件找不到安装目录就不舒服.一开始在系统盘找不到Wi ...

  2. Web框架本质及第一个Django实例

    Web框架本质 我们可以这样理解:所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端. 这样我们就可以自己实现Web框架了. 半成品自定义web框架 impor ...

  3. git 本地代码冲突解决,强制更新

    git reset soft,hard,mixed之区别深解 git reset --hard  强制更新覆盖本地   GIT reset命令,似乎让人很迷惑,以至于误解,误用.但是事实上不应该如此难 ...

  4. UML在代码中的展现

    依赖:一个类使用了另外一个类,这种关系是临时的.脆弱的. 如人需要过河,需要船,这时人.过河(船)  中船被当做参数传入,船的实现变化会影响过河方法.     聚合:体现是整体与部分.has-a的关系 ...

  5. C++中endl和cout语句

    cout是什么?它是一个对象,它代表着计算器的显示器屏幕. 在c++里,信息的输出显示可以通过使用cout和左向‘流’操作符(<<)来完成 这个操作符表面了从一个值到控制台的数据流向! c ...

  6. Linux学习之路3-HelloWorld

    1.window系统上创建helloworld.c文件,并编写程序 #include <stdio.h> main(){ printf("Hello World!"); ...

  7. Fedora 24系统基本命令

    Fedora  24基本命令 一.     DNF软件管理 1.        修改配置:在/etc/dnf/dnf.conf中加入fastestmirror=true.keepcache=true ...

  8. Forethought Future Cup - Elimination Round

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long char getc(){char c=get ...

  9. Apache Flink教程

    1.Apache Flink 教程 http://mp.weixin.qq.com/mp/homepage?__biz=MzIxMTE0ODU5NQ==&hid=5&sn=ff5718 ...

  10. POJ2975 Nim 【博弈论】

    DescriptionNim is a 2-player game featuring several piles of stones. Players alternate turns, and on ...