Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

input type = file problem

 
saravanan balakrishnan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i'm using <input type="file" name="filename1"> in my jsp.when i was trying to get the parameter in my servlet using getParameter method,i'm getting only null.why is it?
can u give me some solution for this.
thanx
 
Metal God
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bala
Precisely what you wanted to retrieve? do you want to retrieve a file contents or the filename?
MG
 
phongtran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bala
Because <input type="file" name="filename1"> is used only for MultiPart form.
So that you must use multipart.getParammter()
About MultiPart, please contact him
// Copyright (C) 1998 by Jason Hunter <jhunter@acm.org>. All rights reserved.
// Use of this class is limited. Please see the LICENSE for more information.
OR, you can download some java class (package cos.jar)
com.oreilly.servlet.multipart.MultipartParser;
com.oreilly.servlet.multipart.Part;
com.oreilly.servlet.multipart.FilePart;
com.oreilly.servlet.multipart.ParamPart;

Bye
Quoc Phong
 
saravanan balakrishnan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
thanx guys for the reply.
i need the filename(from my local system,for example,C:\com\) to my servlet.is there any other method other than Multipart?
thanx
 
phongtran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
You can to use hidden field in your form
When you submit, you use JavaScript to get your fileName
And then, in your servlet, you must use mutilPart.getParameter() to get your fileName
Example:
In your HTML file
<FORM NAME="UploadFile" ACTION="" ENCTYPE="multipart/form-data" METHOD=POST>
<input type="FILE" name="file" value="">
<input type="hidden" name="fileName" value="">
</FORM>
<script language="JavaScript">
function onSubmit() {
fileName.value = file.value;
}
</script>
In your Servlet file
fileName = multiPart.getParameter("fileName");
Have fun, this is my idea, ;-)
Quoc Phong
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic