dcsimg
problem about get the right attached file name
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   diger_qiu
Posted On:   Wednesday, July 17, 2002 08:41 PM

when i get a mail with attached file, i will click my right mouse and press 'save' to save the attached file, then a dialog box appear, and a default filename is in the box. but the name is not the name of attached file, the name always is 'attachment'. i don't know what is the problem of my programm. please help me with it. Thank u very much. Here is some of my programm: receive.jsp [a href="attachment?message=[%=msginfo.getNum()%]&part=[%=showattachments.g etNum()%]"] [%=showattachments.getAttachment().getFilename()%][/a] In this page, the list file name is right. web.xml [servlet-mapping] [servlet-name]AttachmentServlet[/servlet-name] [url-pattern]attachment[/url-pat   More>>

when i get a mail with attached file, i will click my right mouse and press 'save' to save the attached file, then a dialog box appear, and a default filename is in the box. but the name is not the name of attached file, the name always is 'attachment'. i don't know what is the problem of my programm. please help me with it. Thank u very much.
Here is some of my programm:

receive.jsp
[a href="attachment?message=[%=msginfo.getNum()%]&part=[%=showattachments.g
etNum()%]"] [%=showattachments.getAttachment().getFilename()%][/a]
In this page, the list file name is right.

web.xml
[servlet-mapping]
[servlet-name]AttachmentServlet[/servlet-name]
[url-pattern]attachment[/url-pattern]
[/servlet-mappinAttachmentServlet.java

AttachmentServlet.java
public class AttachmentServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

HttpSession session = request.getSession();
int msgNum = Integer.parseInt(request.getParameter("message"));
int partNum = Integer.parseInt(request.getParameter("part"));
Message msg = mailuser.getFolder().getMessage(msgNum);
Multipart multipart = (Multipart)msg.getContent();
Part part = multipart.getBodyPart(partNum);

String sct = part.getContentType();
ContentType ct = new ContentType(sct);
response.setContentType(sct);
ServletOutputStream out = response.getOutputStream();
InputStream is = part.getInputStream();
int i;
while ((i = is.read()) != -1) {
out.write(i);
}
out.flush();
out.close();
}
}

   <<Less

Re: problem about get the right attached file name

Posted By:   gurpreet_ahluwalia  
Posted On:   Wednesday, August 7, 2002 04:02 AM

hii...


i had also faced this prob before...



i think u r missing the file name when u r writting the attachment to the browser....


this is done by response header...


do this.....


response.setHeader("Content-Disposition","attachment; filename=""+ part.getFileName()+ """);

Re: problem about get the right attached file name

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, July 18, 2002 08:21 AM

a default filename is in the box. but the name is not the name of attached file, the name always is 'attachment'



What information tells you what the "name of the attached file" is supposed to be?



(the optional "Content-Disposition" MIME header is the place that the sender can put a suggested filename, but if this header is not present, then on the receiving end your program has no such suggested filename)

About | Sitemap | Contact