java异常java.lang.reflect.InvocationTargetException 并且同时带有空指针异常
2017-10-20 23:48
225 查看
java.lang.reflect.InvocationTargetException 并且同时带有空指针异常,
该错误来源于,实现用户自动登录功能时:登录界面,当输入用户名和密码后,没有勾选自动登录按钮,结果在UserServlet中实现方法时,只要有getParameter(“autologin”);就报错,
分析:用过滤器实现对getParameter方法包装设计增强时,没有加入空指针异常判断。所以在servlet方法中使用自定义的getParameter时,当用户没有勾选自动登录按钮,获取到的是空。所以会报此错误。
解决:在对getparameter方法包装设计进行功能增强时,加入对获取的参数进行空指针判断。或者把异常抛掉一个大异常catch(Exception e){}
异常代码截图:
该错误来源于,实现用户自动登录功能时:登录界面,当输入用户名和密码后,没有勾选自动登录按钮,结果在UserServlet中实现方法时,只要有getParameter(“autologin”);就报错,
分析:用过滤器实现对getParameter方法包装设计增强时,没有加入空指针异常判断。所以在servlet方法中使用自定义的getParameter时,当用户没有勾选自动登录按钮,获取到的是空。所以会报此错误。
解决:在对getparameter方法包装设计进行功能增强时,加入对获取的参数进行空指针判断。或者把异常抛掉一个大异常catch(Exception e){}
class MyRequest extends HttpServletRequestWrapper { public MyRequest(HttpServletRequest request) { super(request); } @Override public String getParameter(String name) { String word = super.getParameter(name); try { if (word == null) { return null; } word = new String(word.getBytes("ISO-8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return word; }} |
相关文章推荐
- 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。
- 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。
- C++带有指针数组的结构体转换为C#可用的结构体
- 三目运算符下的空指针异常和自动拆装箱
- 异常不可能全部同时发生
- view中setImportantForAccessibility调用时莫名其妙的空指针异常
- web如何全局捕获ajax异常并且显示到客户端页面
- 通过指针对字符串进行查询并且替换其中的指定字符
- 如何解决“不允许有匹配 "[xX][mM][lL]" 的处理指令目标。”的异常信息。同时提供几个spring xml配置文件标头!(干货)
- 接受int形参(double,,等等)返回int(...);并且一个vector对象保存指向这些函数的指针;进行加减乘除;输出结果
- NullPointerException 空指针异常
- 一个tomcat同时部属多个项目并且用不同的端口进行访问
- Tomcat 7.0.3x 启动慢并且遇到StackOverflowError的异常的解决办法
- struts action中获取到的对象,报指针异常
- 关于创建对象数组的引用数据类型空指针异常问题
- IL Discovery 系列三 《为什么在遍历List<T>对象时同时删除其中项会抛出异常》
- 在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常
- ASP.NET上传视频文件同时转换为flv并且抓取第一帧生成图片
- Qt中指针异常问题解决
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法