Solved

ServletFileUpload java.lang.NullPointerException

Posted on 2008-10-16
3
725 Views
Last Modified: 2013-11-24
Hi

I have a File upload on a jsp page, if I do not upload and press submit, it throws java.lang.NullPointerException

I use

boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart)
then upload file

Can ServletFileUpload == null then redirect to another jsp page?

0
Comment
Question by:techques
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 22737430
you can put some javascript validation for this?

if(document.forms[0].fileupoload.value="")
alert("Please upload file")
else
redirect to ur jsp;;
0
 

Author Comment

by:techques
ID: 22737702
I use the following code to check whether the upload file is in the right format extension.

However, once I use it and it cannot pass the variable to servlet and throw nullpointerexception.

How can I fix it?

<script language="JavaScript">
    extArray = new Array(".jpg", ".png", ".gif");
    function LimitAttach(form, file) {
    allowSubmit = false;
    if (!file) return;
    while (file.indexOf("\\") != -1)
    file = file.slice(file.indexOf("\\") + 1);
    ext = file.slice(file.indexOf(".")).toLowerCase();
    for (var i = 0; i < extArray.length; i++) {
    if (extArray[i] == ext) { allowSubmit = true; break; }
    }
    if (allowSubmit) return true;
    else
    alert("Please only upload files that end in types:  "
    + (extArray.join("  ")) + "\nPlease select a new "
    + "file to upload and submit again.");
    return false;
    }
</script>
 
OnSubmit="return LimitAttach(this.form, this.form.myimage.value)"
 
servlet:
boolean isMultipart = ServletFileUpload.isMultipartContent(request);

Open in new window

0
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 50 total points
ID: 22737907
can't you write like this
if (allowSubmit)
{
document.forms[0].action="/ServletFileUpload?action=fileupload&file="+the file u want to upload
return true;
}
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapBully challenge 6 177
word0 challenge 3 112
eclipse apache tomcat admin console 52 154
maven disable workspace resolution 1 41
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question