java异常java.lang.reflect.InvocationTargetException 并且同时带有空指针异常

java.lang.reflect.InvocationTargetException  并且同时带有空指针异常,

该错误来源于,实现用户自动登录功能时:登录界面,当输入用户名和密码后,没有勾选自动登录按钮,结果在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;

    }}

                                          异常代码截图:

 

 

posted @ 2017-10-20 23:48  woa糊涂虫  阅读(2875)  评论(0编辑  收藏  举报