JSP Upload File Java.lang.NullPointer

Posted by newbie123 on Stack Overflow See other posts from Stack Overflow or by newbie123
Published on 2010-05-29T10:15:16Z Indexed on 2010/05/29 10:22 UTC
Read the original article Hit count: 248

Filed under:
|

I want to develope upload and download file from server.

Upload.html

<form action="/UploadFile/UploadFile" method="POST"
enctype="multipart/form-data">Select a file: <input
type="submit" name="button" /> <input type="file" name="first"></form>

UploadFile.servlet

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    String temp = request.getParameter("first");
    System.out.println(temp);
    File origFile = new File(temp);
    FileOutputStream out = new FileOutputStream(request.getContextPath()
            + "pdtImages/" + "FirstFile");
    InputStream ins = new FileInputStream(origFile);
    try {
        System.out.println(request.getContextPath());
        byte[] buf = new byte[1024];
        int len;
        while ((len = ins.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

When I submitted the file I got null pointer error message. I not very familiar with jsp can anybody help me? I want to store the file to the server directory.

© Stack Overflow or respective owner

Related posts about jsp

Related posts about fileupload