• Post Reply Bookmark Topic Watch Topic
  • New Topic

session variable for file upload box  RSS feed

 
Matthew Turner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey everyone, i am currently looking to get the filename from a file upload box on my html page and use it as a string on my jsp page,

on my HTML page,
<input type="file" name="fileName" size="15">

and on my jsp page,
String fileName = request.getParameter("fileName" );

this does not work, as 'fileName' seems to be staying null(i am guessing it does not return a string), can someone help me to get the file name as text?
What type does it return?

thanks for any help you can give me,

cheers,
Matt T
 
irfan ahmed
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt,




STEP 1********************************
in ur html code add-----------

ENCTYPE="multipart/form-data"
-------------------
*****************************************


step 2
**********************************************

http://www.jguru.com/faq/view.jsp?EID=160
************************************************
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
describe your form like:

<form name="formReport" action="FileUploader" method="post" enctype="multipart/form-data">
.. .
....
</form>

after doing this in your servlet again you will get null from request.getParameter("fileName"), it is the fact. try this out:

commons-fileupload-1.0.jar

the urls are:

tutorial -
http://jakarta.apache.org/commons/fileupload/using.html

download file -
http://jakarta.apache.org/commons/fileupload/index.html

hope it will help you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am assuming that your file element is in an HTML form that has specifies an enctype of a multipart form?

If so, request.getParameter() will not work. This method will only obtain parameters when the enctype of the form is "application/x-www-form-urlencoded" (the default).

In other words, when performing a file upload, you are on your own as far as parsing the multi-part request, including the parameters. Which is why most people rely upon already-written libraries to parse multi-part requests.

Check out here for one of them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!