MIME Multipart/related to embed images in html files - Servlet

Hello,
My goal is to embed images in html/xhtml files to decrease latency when using slow networks. Think about mobile phones, if I have 10 images in one page, I will have 11 requests/responses to get the whole page.
The solution would be to embed all images using Content-type multipart/related, so I have one request to the whole pack.
How to do that in java? I mean, I need to set the content-type and build all parts encoding the images to base64.
I tried JavaMail API, there I can build messages like this and instead of send an e-mail, I can write:
myMimeMultipart.writeTo(response.getOutputStream());
The problem is: I am getting everything as text in my browser, including the MIME headers of each part. Another think is that the first header (the main one) doesn't appear too.
Any thoughts/other ideas?
Thanks in advance,
Andr� Carlucci

If memory serves me right, I believe in the Servlet spec you have access to the Response object. You "should" be able to set any headers you need there. In addition, you can get the output streams just as you described.
I did a similar thing, although slightly modified, to output dynamically-generated XLS (Excel Spreadsheet) files using a reporting engine called JasperReports. It wasn't a multipart response, however, so you may need to figure out how to handle that part of it, but in my case I set the mime-type header, then grabbed the output and started writing my XLS file too it. Once done, you close the streams and return the response. Worked perfect.

Similar Messages

  • How to embed images in HTML

    i was wondering if i could embed images into html and end up with a single file

    olafgarten212 wrote:
    i was wondering if i could embed images into html and end up with a single file
    No you can't.  An image file is an image file while HTML file is simply a text file that can be read and edited with any text editor.  Image files can't be edited in the normal way without the use of special programs like Photoshop, fireworks, and other free ones that can be downloaded.
    However, as your question is vague as pointed out by Nancy O, I would hazard to guess that you want to save a webpage that can be viewed off-line.  If this is the case then I suggest use Internet Explorer to save the page as .mht file.  This will allow you to have a complete page including images and style sheets all in one file.
    The file is saved as:  File >> save as >> "myfile.mht"
    The saved file is a single web archive, single file that can also be edited in Microsoft Word.
    Good luck.

  • [svn] 609: Changed the svn:mime-type of the SDK's milestones.html file.

    Revision: 609
    Author: [email protected]
    Date: 2008-02-21 14:47:48 -0800 (Thu, 21 Feb 2008)
    Log Message:
    Changed the svn:mime-type of the SDK's milestones.html file.
    Property Changed:
    flex/sdk/milestones.html

    the web xml mime type setting are for static files served by the server...
    if you print a file directly to the output of the servlet, you must set the mime type, so DO write :
    response.setContentType( "application/vnd.ms-excel" );
    IE "works fine" because it also uses the file extension to decide the mime type... but in the absolute, it's a wrong behaviour

  • Why can't I drag an image or html file into a browser window with Firefox 17

    to get a quick view of various images or html files, I like simply dragging the files from my local drive into a Firefox browser window.
    since upgrading to FF 17, I can no longer do that. a NO symbol comes up when attempting this. and Dreamweaver will no longer preview with Firefox, even though it's my designated, preferred browser.
    anybody know if both of these are some setting or something?

    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do not click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Pick Image from Html file

    I want to retrieve the image from html file & then save this file in jpg format.
    I have a html file with following contents.
    Patient id = 1
    Dated = 03/06/2008
    Pcr_Volume = 0.5
    Notes:
    Principle :
    after principle heading there is a graph file attached.
    Result:
    Remarks:
    I want to pick this graph file which is present after Principle heading and save it to jpg format.
    Regard's

    I want to pick Image(which is actually a graph image of patient test). This image is present is html file with some contents and this file is auto generated by the machine in which test perform.
    I just open that html file and click on that image which is pasted in between that html file when i clik on that image a toolbar appear with save & some other button & then I press
    save button and save that image in jpg format.
    After that i use this image to display in patient report.

  • How to embed image in html when using JTextPane, HTMLEditorKit, JavaMail

    I am developing a specialized e-mail client that has to be able to send e-mail messages (in html format with images and attachments) that can be read by standard e-mail clients, and receive similar messages from standard e-mail clients.
    I have everything working except for embedding images.
    Images are to appear in the document mixed in with the text, but that's not what I mean by "embed". By "embed" I mean that the image itself is encoded within the html.
    Here's a bit of code to set the context.
    JTextPane bodyPane = new JTextPane();
    bodyPane.setEditorKit(htmlEditorKit);
    bodyPane.setTransferHandler(new DropHandler());
    bodyPane.setDocument(new HTMLDocument());
    In the DropHandler I have the following:
    HTMLDocument htmlDoc = (HTMLDocument) bodyPane.getDocument();
    HTMLEditorKit htmlKit = (HTMLEditorKit) bodyPane.getEditorKit();
    int caretPos = bodyPane.getCaretPosition();
    At this point get "filename", the full path to an image file that has been dropped onto bodyPane.
    String htmlString = "<img src=\"file:///" + filename.replace("\\","/") + "\">";
    htmlKit.insertHTML(htmlDoc, caretPos, htmlString, 0, 0, HTML.Tag.IMG);
    This works just fine. The image is displayed in the document at the point of insertion.
    However, the image itself is an external file. I need to send an e-mail with this image and could send the image file as an attachment, but I obviously can't assume that the recipient of the email is going to save the attachment into the proper location.
    What is the best way to do this?
    There is a technique for embedding the actual image in the html, using this syntax:
    String htmlString = "<a href=\"data:image/png;base64,---mimed png image here--\" alt=\"Red dot\"></a>";
    I can't get this to work in JTextPane, so perhaps it's not supported. Also, there may be limitations on the size of an image. And apparently Internet Explorer doesn't support this.
    From what I read, using a "content identifier", that is, "cid:" and adding the image as another part of the e-mail message is probably the thing to do. I haven't taken the time to explore this yet.
    Does JTextPane support cid? Is that a nonsense question? I suspect what I need to do when the message is being composed is use absolute paths to local files with the images, and then when assembling the e-mail, attach the files and rewrite the html to build in the cid linkage. Similarly, when reading a message with cid's, the thing to do is save the body parts as files and rewrite the cid to point to the actual file.
    I have seen others ask similar questions, one as recently as last December, and the reply was to refer to a Sun tutorial. But that tutorial doesn't address the full problem of 1) inserting an image into a document (instead of attaching an image to a component) and 2) sending it as an e-mail message.
    I have yet to see an example that shows the complete package.
    Am I right that the data option I mentioned is not going to work?
    Am I right that cid is the best approach, and do I understand how to use it?
    Is there something else?
    Thanks
    John

    Hi Rocky,
    Are you using the DC?
    if yes then you need to put the image inside the component folder. after that close the application
    & reopen. You will get the image.
    In case this does not work then try refreshing the portal through server side. Once the cache is cleared, it will be up to view.
    Also check the Activity list you have created. It should be added to the dtr properly or else it wont be reflected once reimported the configurations.
    Regards
    Chander Kararia

  • Embed images into HTML

    Hi, I want to create an email template, I have designed a Dreamweaver page. the images need to be embedded within the HTML document. any help will be welcome.
    Graham

    meki G wrote:
    Hi, I want to create an email template, I have designed a Dreamweaver page. the images need to be embedded within the HTML document. any help will be welcome.
    Graham
    What I tend to do is just link all the images normally so you can see what's going on.
    <img src="images/something.jpg" width="400" height="367" alt=""/>
    Then when I'm happy with the final design I'll go through the code and change the paths to the images so they are absolutely linked.
    <img src="http://www.yourWebAddress.com/images/something.jpg" width="400" height="367" alt=""/>
    Upload your images to the server in the 'images' folder.

  • Oracle 11g Forms Configuration Forms.conf  (Image and Html files)

    Hello,
    We are configuring our forms.conf file as such.
    AliasMatch ^/forms/help/(..*) "/u01/app/forms/as_1/forms/appname/help/$1"
    AliasMatch ^/forms/icons/(..*) "/u01/app/forms/as_1/forms/appname/icons/$1"
    AliasMatch ^/forms/images/(..*) "/u01/app/forms/as_1/forms/appname/icons/$1"
    However when I go to
    https://server/forms/help/help.pdf
    I get 404 .
    Is there something I am missing here. file permissions are read across the board and the directory exists.
    Is there some other configuraiton I am missing.
    Thanks!

    Was able to fix this problem.
    The following is hte resolution.
    In plan.xml
    1. At the very top create a variables.
    <variable>
    <name>vd-application</name>
    <value>/u01/middleware/wls_forms/forms/forms</value>
    </variable>
    <variable>
    At the bottom Add
    <variable-assignment>
    <name>vd-application</name>
    <xpath>/weblogic-web-app/virtual-directory-mapping/[url-pattern="help/*"]
    /local-path</xpath>
    </variable-assignment>

  • When I download an excel spread sheet from a Ford web site I seem to be getting code and not the work sheet. Example- MIME-Version: 1.0 X-Document-Type: Workbook Content-Type: multipart/related; boundary="====Boundary===="

    I have a Macbook Air. I have MS office installed and work in Excel often with no issues. But When I download an excel spread sheet from a Ford web site I seem to be getting code and not the work sheet.
    Example-
    MIME-Version: 1.0
    X-Document-Type: Workbook
    Content-Type: multipart/related; boundary="====Boundary===="
    --====Boundary====
    Content-Location: file:///C:/HOLD.XHT
    Content-Transfer-Encoding: 8bit
    Content-Type: text/html; charset="utf-8"
    <html xmlns:v="urn:schemas-microsoft-com:vml"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40">
    <HEAD>
    <meta name="Excel Workbook Frameset">
    <xml>
    <x:ExcelWorkbook>
      <x:ExcelWorksheets>
       <x:ExcelWorksheet>
        <x:Name>BTB</x:Name>
        <x:WorksheetSource HRef="./IBIT0001.xht"/>
       </x:ExcelWorksheet>
       <x:ExcelWorksheet>
        <x:Name>GSM</x:Name>
        <x:WorksheetSource HRef="./IBIT0002.xht"/>
       </x:ExcelWorksheet>
       <x:ExcelWorksheet>
        <x:Name>RODetail</x:Name>
        <x:WorksheetSource HRef="./IBIT0003.xht"/>
       </x:ExcelWorksheet>
      </x:ExcelWorksheets>
    </x:ExcelWorkbook>
    </xml>
    </HEAD>
    </HTML>
    --====Boundary====
    Content-Location: file:///C:/IBIT0001.xht
    Content-Transfer-Encoding: 8bit
    Content-Type: text/html; charset="utf-8"
    <html xmlns:v="urn:schemas-microsoft-com:vml"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40">
    <HEAD>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
    <style>
    <!--table
            {mso-displayed-decimal-separator:"\.";
            mso-displayed-thousand-separator:"\,";}
    @page
            {margin:1.0in .75in 1.0in .75in;
            mso-header-margin:.5in;
            mso-footer-margin:.5in;
            mso-page-orientation:landscape;}
    tr
            {mso-height-source:auto;}
    col
            {mso-width-source:auto;}
    br
            {mso-data-placement:same-cell;}
    .style21
            {color:blue;
            font-size:10.0pt;
            font-weight:400;
            font-style:normal;
            text-decoration:underline;
            text-underline-style:single;
            font-family:Arial;

    Try search/ask in the forum devoted entirely to Excel issues:
    http://answers.microsoft.com/en-us/mac/forum/macexcel

  • How to include image or html dynamically in a JSP?

    I need to show the uploaded content in a jsp. It could be either a image or html file. How can i include these images or html files dynamically without affecting screen design.

    What the heck is 'screen design'? You mean the page layout?
    You could show in a popup div; JQuery will be your best bet for a prebuilt function to do that. But you'd need to put the uploaded file in a place where the browser can fetch it through an URL, or you need to create a servlet that can load and return the data to the browser.

  • Error in exporting REPORT image or HTML

    I have been receiving an error recently while trying to export a REPORT into an image format or HTML.  I receive this error:
    "Cannot open clipboard.  (Error code 0)"
    Has anyone received this error before?  I have been able to export images and HTML files before, and I am not sure what I have done to change my system.
    Thank you,
    Julia

    Hi,
    I think I found the problem.  I have been experiencing clipboard problems lately with Microsoft Office products.  It appeared as though my clipboard would stop working after I would do a lot of copying and pasting.  Rebooting my computer fixed the problem.  After searching for help, it seems that my problem involves connecting remotely to a Windows 2003 server, which I do often.  If the connection is open, copying and pasting sometimes does not work on my computer.  It appears I am having a similar problem with DIAdem.  If I am remotely connected to a server, I cannot export images.  When I disconnect, everything works.  I thought that was a really strange problem, but maybe if anyone else has the problem, this might help.
    Julia

  • KM, HTML file, Not rendering correctly

    Hi Everyone
    I have an html file that is stored in knowledge management.  The html file references few folders/images that are also stored in KM. When I create a KM Document iView, the HTML file shows; however, the various images/style sheet that is stored along with the html file KM do not appear.  Thus the html file is not rendering properly. 
    With this being said, I can create an URL iview and everything works as it should (the html file appears correctly with the necessary images).  The problem is that I am developing a solution for an external and internal facing portal, thus the URL iView option is not going to work for me.  I need to have a way for this KM html iView to display properly...perhaps with the KM Document iView template.
    Has anyone encountered an issue such as this and can offer assistance.  Again, the KM Document iView template will work, if the html file it is calling in KM can correctly reference other folders in KM that contain various images/style sheets that are a part of the html file.
    Any help is greatly appreciated.
    Best Regards,
    Scott

    Hi Scott.
    In order to solve your problem with relative links to image and css files inside KM I suggest two variants:
    1. Replace relative links as I mentioned in this message Re: JavaScript and CSS info in WPC.
    2.The second solution is:
    a. Create an blank html file inside KM folder where the base.html file is stored.
    b. Download the newly created file for local editing.
    c. Place an iframe that points to your base html file between <BODY></BODY> tags. Use a following code as an example:
    <iframe width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="base.html"></iframe>
    d. Upload this file back to KM.
    e. Point your KM Document  iView to the created html file.
    Best regards,
    Aliaksandr Zhukau
    Edited by: Aliaksandr Zhukau on Dec 3, 2009 11:04 AM

  • How to send HTML mail with images multipart/related message

    Hi,
    Could any body tell me how to send HTML mail with images in "multipart/related" message,if any body can give the code ,it would be helpful.
    Thanks

    Hi,
    Could any body tell me how to send HTML mail with
    ith images in "multipart/related" message,if any body
    can give the code ,it would be helpful.
    ThanksHi!
    Refer to
    http://developer.java.sun.com/developer/onlineTraining/JavaMail/index.html
    I've found it very helpful.
    Look at the last part for a code showing how to send HTML mail!
    Regards

  • No object DCH for MIME type multipart/related

    Hi, everyone!!!
    When I execute my code, I got this exception:
    javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/related
    boundary="----=_Part_0_20851530.1186777547859"
    the funny things is : I got it work before. However, when I come back a few days to run, it doesn't.
    I use tomcat 5.0,
    mail.jar: version: 1.6
    activation.jar:version: I don't know but I download the new ones in sun website.
    Note: Also, when I run the code below in standalone application (java application), it works but doesn't work on tomcat application
    Any help would be appreciate.
    I tried some helps tips from other website such as http://www.jguru.com/faq/view.jsp?EID=237257
    and still doesn't work :((((
    ***********Here is my code**********
    ********props is properties file...............
    Authenticator auth = new SMTPAuthenticator();
              // Get session
              Session session = Session.getDefaultInstance(props, auth);
              session.setDebug(true);
              // Create the message
              Message message = new MimeMessage(session);
              // Fill its headers
              message.setSubject(subject);
              message.setFrom(new InternetAddress(from));
    for(int x=0;x<recipients.size();x++)
         message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients.get(x).toString()));
                        // Create your new message part
                        BodyPart messBodyPart=new MimeBodyPart();
                        // Set the HTML content, be sure it references the attachment
                        String htmlText="<h1>Hi</h1>"+"<img src=\"cid:picture\">";
                        // Set the content of the body part
                        messBodyPart.setContent(htmlText, "text/html");
                        // Create a related multi-part to combine the parts
                        MimeMultipart multipart=new MimeMultipart("related");
                        // Add body part to multipart
                        multipart.addBodyPart(messBodyPart);
                        // Create part for the image
                        messBodyPart=new MimeBodyPart();
                        // Fetch the image and associate to part
                        System.out.println("before dataSource");
                        DataSource fds=new FileDataSource(this.getString("image_location"));
                        System.out.println("After dataSource");
                        messBodyPart.setDataHandler(new DataHandler(fds));
                        System.out.println("*************** dataSource");
                        // Add a header to connect to the HTML
                        messBodyPart.setHeader("Content-ID", "<picture>");
                        // Add part to multi-part
                        multipart.addBodyPart(messBodyPart);
                        // Associate multi-part with message
                        message.setContent(multipart);
                        // Send message
                        System.out.println("Before Send");
                        Transport.send(message);
                        System.out.println("Finish");
    }

    Thank you for your response!!!
    I already found the solution. For those who still having problem send e-mail, make sure to put mail.jar and activation.jar in the same location.
    Also, make sure to check catalina.xml to make sure those jars are same location!!!->That what I found out.
    ->I put jars in same location of my eclipse project but it turns out, the tomcat app server didn't put them in same location.
    Anyway, Thank you java_2006 for your response!!!!!
    :)

  • HTML Files in portal that access relative images

    We put html files on some of our pages. These open up and display their contents, which include images. These images we store on the same portal page (but hide them) so the html page has access to them in the same directory. So, we basically, use a portal page as a web server directory to put the html, css, images, etc.
    Is this going to break in a future version of portal?
    According to:
    http://download-west.oracle.com/docs/cd/B14099_19/portal.1014/b13809/apdxurls.htm
    "Following this release, path-based URLs that follow the following syntax will be obsolete"
    That sounds to me like my above scenario will break. Yes?
    Thanks.

    Why do you use html files exactly ? Because, we have legacy HTML documents that are from our pre-portal intranet days. We were able to just stick them into a portal page and they worked. And, the nice thing is that they can link to each other with relative links within the same directory/path. So, it's not just images. We really don't care that much about images, that was just an example that would be easy for people to understand. Using the /images folder does not solve most of problem. And, like I mentioned before, we also have PDFs with PDF-to-PDF web links where they all link to each other with relative links within the same directory. We also have some Flash (swf) files that take advantage of page-path URLs.
    It's not like our whole portal is made up of HTML documents. But, we used many of them instead of Word or PDF documents, because that's what we had from before. So, in most cases we can convert them to PDFs. But, there are some cases where we have mini websites made up of HTML files all stuck into a Portal page. These, and the PDF-to-PDF linked documents are a bigger problem.
    This is a major headache that we are not looking forward to.

Maybe you are looking for