关于jsp页面中接收二维数组

 

正确写法

        <%String[][] blog = new String[5][];
        blog[0] = request.getParameterValues("blog0"); 
        blog[1] = request.getParameterValues("blog1");
        blog[2] = request.getParameterValues("blog2"); 
        blog[3] = request.getParameterValues("blog3");
        blog[4] = request.getParameterValues("blog4"); 
        for(int i=0;i<blog.length;i++){
            if(blog[i]==null){
                blog[i]=new String[5];
                blog[i][0]="博客题目";
                blog[i][1]="博客分类";
                blog[i][2]="博客时间";
                blog[i][3]="博客前80字";
            }
        %>

不能写作

        <%String[][] blog = new String[5][5];
        blog[0] = request.getParameterValues("blog0"); 
        blog[1] = request.getParameterValues("blog1");
        blog[2] = request.getParameterValues("blog2"); 
        blog[3] = request.getParameterValues("blog3");
        blog[4] = request.getParameterValues("blog4"); 
        for(int i=0;i<blog.length;i++){
            if(blog[i]==null){
                blog[i][0]="博客题目";
                blog[i][1]="博客分类";
                blog[i][2]="博客时间";
                blog[i][3]="博客前80字";
            }
        %>

否则会报

Stacktrace:] with root cause
java.lang.NullPointerException

即blog[i][0]="博客题目";指针找不到错误。

posted @ 2019-10-07 14:26  蓝色风扇  阅读(863)  评论(0编辑  收藏  举报