File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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"))
{
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>


Sun Certified Programmer for Java Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enctype Error
 
Similar Threads
Logout Code is not working
perform a specific task on logout/closing of browser
session management problem with iframes
Regarding xml Data
logOut script not working