今天做jsp页面时,遇到错误java.lang.NumberFormatException: null
查了一下问题发现是:
parseInt转换会触发NumberFormatException异常。
int id=Integer.parseInt(request.getParameter(“xxid”));
这种异常,一般是当request.getParameter(“xxid”)包含非数字字符,或为null的时候出现。
当出现这个null问题时一定要认真梳理思路,看看页面请求时的参数是否真的传入进去,根据request的范围查看传入参数是否层层传递。
parseInt转换时获得null出现问题,重复找过代码发现代码没有错误,
在jsp页面中的
<form id=“form” action=“login” method=“post” enctype=“multipart/form-data”>
删除掉enctype属性就解决了问题。
对enctype属性的理解:
enctype 属性规定在发送到服务器之前应该如何对表单数据进行编码。
默认地,表单数据会编码为 “application/x-www-form-urlencoded”。
当时没有文件上传所以可以去掉enctype属性
request.getParameter()取值为空的问题
最新推荐文章于 2024-06-22 08:00:00 发布