jsp上传图片和视频java.lang.NumberFormatException

时间:2014-07-08 10:37:12

标签: jsp

java servlet-java.lang.NumberFormatException:null

您好,我编写了一个jsp和一个servlet,用于将文本信息,视频和图像数据输入数据库。

基本上,控件从AddDataInfo.jsp传递到AddDataInfoServlet.java

这是AddDataInfo.jsp的代码

<body>

<form action="addDataInfoServlet" method="post" enctype="multipart/form-data">
    <% 
        String tabId =  request.getParameter("tabId");
        out.println("tabId  " + tabId);
        out.println("<br/>");
        String categoryId =  request.getParameter("categoryId");
        out.println("categoryId  :" + categoryId);
        out.println("<br/>");
        String subCategoryId =  request.getParameter("subCategoryId");
        out.println("subCategoryId  " + subCategoryId);
        out.println("<br/>");
        String attributeId =  request.getParameter("attributeId");
        out.println("attributeId  " + attributeId);
        out.println("<br/>");
    %>
    <% 
        if(attributeId!=null){

    %>
    <input type="hidden" name="attributeId" value=<%=attributeId%>>
    <br/>

    <%=attributeId %>
    <br/>
    <% 
        }
    %>
    <input type="hidden" name="tabsId" value=<%=tabId%>>
    <input type="hidden" name="categoryId" value=<%=categoryId%>>
    <input type="hidden" name="subCategoryId" value=<%=subCategoryId%>>


    Information: <input type="text" name="information" /><br/>
    Image Name: <input type="text" name="imageName"/><br/>
    Image Description: <input type="text" name="imageDescription" /><br/>

    Image:  <input type="file" name="image" />
<br /> 
    Video Name: <input type="text" name="videoName"/><br/>
    Video Description: <input type="text" name="videoDescription"/><br/>

    <!--  Video:    <input type="file" name="video" />-->
    Video:  <input type="file" name="video" />
    <input type="submit" value="Upload" />
</form>


</body>

AddDataInfoServlet.java的代码

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}


public void processRequest(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException{

    try{
        HttpSession session= request.getSession();
        DataManagerDao dao = new DataManagerDao();
        DataInfo dataInfo = new DataInfo();

        if(ServletFileUpload.isMultipartContent(request)){
            try{
                 for(FileItem item : multiparts){

                   switch(item.getFieldName()){
                        case "tabsId":
                            tabId  = item.getString();
                            System.out.println("tabId " + tabId);
                            break;
                        case "categoryId":
                            System.out.println("categoryId ABC" );
                            categoryId = item.getString();
                            System.out.println("categoryId " + categoryId);
                            break;
                        case "subCategoryId":
                            subCategoryId = item.getString();
                            System.out.println("subCategoryId " + subCategoryId);
                            break;

                        case "attributeId":
                            attributeId = item.getString();
                            System.out.println("attributeId " + attributeId);
                            break;

                        case "information":
                            Information = item.getString();
                            System.out.println("Information " + Information);
                            break;

                        case "imageName":
                            ImageName = item.getString();
                            System.out.println("ImageName " + ImageName);
                            break;
                        case "imageDescription":
                            ImageDescription = item.getString();
                            System.out.println("ImageDescription " + ImageDescription);
                            break;

                        case "videoName":
                            videoName = item.getString();
                            System.out.println("videoName " + videoName);
                            break;  

                        case "videoDescription":
                            videoDescription = item.getString();
                            System.out.println("videoDescription " + videoDescription);
                            break;  

                        default:
                            System.out.println("INVALID parameter");
                    }

              dataInfo.setDataTabId(Integer.parseInt(tabId));
            ..........

            }
        }

        }
    }
} 

但是,我得到一个java.lang.NumberFormatException:null

在这一行:dataInfo.setDataTabId(Integer.parseInt(tabId));

我仔细检查jsp文件中的值,它们不是空的

请帮忙

1 个答案:

答案 0 :(得分:0)

持有标签的隐藏输入字段似乎拼写错误拼写为tabsId

<input type="hidden" name="tabsId" .....

并且scriptlet正在尝试将其检索为tabId