2 tiacex tiacex 于 2014.02.05 20:54 提问

jsp页面ArrayList数据错误…求救求救啊啊,困扰几天了…



<%
ArrayList viewFile = (ArrayList)session.getAttribute("viewFile");
ArrayList storyFile = (ArrayList)session.getAttribute("storyFile");
ArrayList creativeFile = (ArrayList)session.getAttribute("creativeFile");
ArrayList varietyFile = (ArrayList)session.getAttribute("varietyFile");
%>
……
    <table border="0" width="680px">
            <tr bgcolor="#FF9900">
                <td colspan="3"><%=viewFile.get(0).fileType.getFileTypeName()%></td>
                <td align="right"><a href="FileListServlet?biaoshi=wu&typeId=1">更多>></a></td>
            </tr>
            <tr>
            <%
                for(int i=0;i<viewFile.size();i++){
                    FileInfo file = viewFile.get(i);
            %>
                <td>
                    <table border="0" align="center">
                        <tr>
                            <td align="center">
                                <a href="showFileInfo.jsp?jihe=viewFile&id=<%=file.getFileId()%>">
                                <img src="uploadfiles/<%=file.getPic1() %>" width="150" height="180" border="0"/>
                                </a>
                            </td>

                        </tr>
                        <tr>
                            <td>
                              <a href="showFileInfo.jsp?jihe=viewFile&id=<%=file.getFileId()%>">
                                <%=file.getFileTitle() %>
                               </a>
                            </td>

                        </tr>

                    </table>
                </td>   
            <%
                }
             %> 
            </tr>

……
……

 ***结果:***

//<%=viewFile.get(0).fileType.getFileTypeName()%>这句报错,里面viewFile就是ArrayList
类型的…有ArrayList的页面就有错误…

org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

java.lang.NullPointerException
org.apache.jsp.show_jsp._jspService(show_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.

2个回答

wangya168
wangya168   2014.02.06 16:08

查查相应的servlet里有没有写绑定名称为viewFile的session,还有转发的语句有写吗?

u011488629
u011488629   2014.02.11 15:42

<%=viewFile.get(0).getFileTypeName()%>或者先强制类型转换一下

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!