• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

getting the uploaded filename for downloading

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
am uploading a file, and after its uploading, the link will go for downloading. Here it is getting the file name as "null" instead of uploaded filename. can you please tell me how the parameters of multi-part/formdata are stored. please i stuck with this from 2 days.

thanks
indu
[ September 04, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post your code snippet here.
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out=response.getWriter();
response.setContentType("text/html");
///out.println("upload servlet... POST ***** ");
boolean ismultipart = ServletFileUpload.isMultipartContent(request);
try
{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
DiskFileItemFactory dfactory= new DiskFileItemFactory();
List items=upload.parseRequest(request);
Iterator iter = items.iterator();

while(iter.hasNext())
{
FileItem item = (FileItem)iter.next();

String fieldname = item.getFieldName();
HttpSession session = request.getSession();
session.setAttribute("filename",fieldname);
// out.println("field name --->>> "+fieldname);
String fieldvalue = item.getName();
// out.println("<br>field value --->>> "+fieldvalue);
session.setAttribute("fieldvalue",fieldvalue);
String contenttype=item.getContentType();
long size = item.getSize();
boolean memory = item.isInMemory();
//String filename=request.getParameter("filename");
//out.println(filename);
File saveTo = new File("/upload_files/myFile.txt");
item.write(saveTo);

}


}
catch(Exception e)
{
e.printStackTrace();
}
RequestDispatcher disp=request.getRequestDispatcher("UploadSuccess.jsp");
disp.forward(request,response);
}
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THis is my uploaded logic, is this is correct way of writing in to a server ?
thanks
indu
 
Karup Mew
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

List items=upload.parseRequest(request);



Check the List object contains the FileItem object
 
Sheriff
Posts: 67682
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
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh, sorry Bear, thanks for your suggestion...
indu
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karup, the List item is not having FileItem object..
 
Karup Mew
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check whether the request object Content Type is multipart/formdata or not.
If possible show the console output also.
[ September 05, 2008: Message edited by: Karup Mew ]
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic