Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

how do i get value from input type file in servlet?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actualy i just want to send an attachment using javamail api....previously my code was working fine suddenly its not working....i did nt use enctype="multipart/form-data" bt it was working fine.
whenever i am using this code means enctype="multipart/form-data" i am getting null value using request.getParameter from servlet as servlet not support it...i just want to know how can i get the value....
And i also want to know what value actualy we should get..means should we gt the actual path of the file means filename="c:/a.doc" or only a.doc.


<form METHOD=post ACTION="action.cgi"
ENCTYPE="multipart/form-data">
<input TYPE="file" NAME="filename">
</form>
I have used daman sidhu's multipart class to solve this problem.
i got null values in myParam;and got .\a.txt value from File f=multi.getFile(name);I think i should gt the full path dat is d:/a.txt.

One more thing after using this code whenever i m trying to get other field
using normal process request.getparameter (name)...i m getting null value...


<form name="form1" ENCTYPE="multipart/form-data" method=post action="http://localhost:8084/mail/mailSms ">
<input type="file" name="fileAttachment1" value="fileAttachment1" id="fileAttachment1">
<input type="submit" value="upload" />
</form>





MultipartRequest multi=new MultipartRequest(request,".",5*1024*1024);

File ff=multi.getFile("fileAttachment1");
out.println(ff);
Enumeration files=multi.getFileNames();
while(files.hasMoreElements())
{
String name=(String)files.nextElement();
String filename=multi.getFilesystemName(name);
String type=multi.getContentType(name);
File f=multi.getFile(name);


}
String myParam=multi.getParameter("fileAttachment1");
out.println(myParam);


please help me in this regard............
thanks in advance
 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Unfortunately, the servlet API provides no high-level tools to read uploaded files;you have to call request.getInputStream and parse the request yourself.
Fortunately,numerous third-party libraries are available for this task.One of the most popular is from the Jakarta Commons library;for details ,see
http://jakarta.apache.org/commons/fileupload/.

Are you using this in Marketing mails project?
[ September 25, 2008: Message edited by: pradeep singh ]
 
Sheriff
Posts: 67671
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is an entry in the JSP FAQ on this subject.
 
Whatever you say buddy! And I believe this tiny ad too:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic