File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Enctype Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Enctype Error" Watch "Enctype Error" New topic

Enctype Error

Stephen Wei
Ranch Hand

Joined: Oct 09, 2001
Posts: 73
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"))
window.event.returnValue = true;


<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>

Sun Certified Programmer for Java Platform
I agree. Here's the link:
subject: Enctype Error
It's not a secret anymore!