Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting the uploaded filename for downloading

 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • 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 ]
 
Karup Mew
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code snippet here.
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
List items=upload.parseRequest(request);


Check the List object contains the FileItem object
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64606
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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 ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic