• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Enctype Error  RSS feed

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all:
I am uploading a file to my servlet. Before doing so, on the client side I use Javascript to check if the file is csv or not. The checking is ok, but then my servlet says Enctype error.
Notice that if I remove the Javacript checking, the file is uploading fine. So what is wrong with my approach? how to fix it?
Following is my code, thanks.
<script language = "javascript">
function fileFormSubmit()
{
var error1 = "please select csv file";
var error2 = "please select GIF file";
window.event.returnValue = false;
var string = uploadForm.fileName.value.substr((uploadForm.fileName.value.lastIndexOf(".")+1));

if ((string != "csv")&&(string != "CSV"))
{
alert(error1);
uploadForm.fileName.onfocus;
}
else{
if(confirm("submit?")){
window.event.returnValue = true;
}
}

return(0);
}
</script>

<form ID="uploadForm" action="../servlet/Upload" METHOD=POST ENCTYPE="multipart/form-data" onsubmit = "fileFormSubmit()">
<p align="center"> <INPUT TYPE=FILE NAME=file1> </p>
<p align="center"> <INPUT TYPE=SUBMIT> </p>
</form>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!