-1

How to view the file without downloading in java using struts frame work? For example in Gmail we view files/resumes in canvas later we download.

JSP:

<div class="modal fade" id="addAttachmentDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <s:form action="add_attachment_form_submit" name="add_attachment_form" theme="simple" id="edit_add_attachment_form_id" enctype="multipart/form-data" method="POST">
            <input type="hidden" name="partyId" id="edit_partyId" value="<%= partyId%>" />
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" title="close" class="close" data-dismiss="modal">×</button>
                     <h3>Upload Attachment</h3>

                </div>
                <div class="modal-body">
                    <table style="table-layout:fixed;width:100%;">
                        <tr>
                            <td width="30%">
                                <label class="control-label" for="edit_referral_source_name">Choose File<span title="Required Field" class="required-marker">*</span>
                                </label>
                            </td>
                            <td width="70%">
                                <%-- <s:file name="fileUpload" label="Select a File to upload" size="40" />--%>
                                <%-- <div id="file_upload-button" class="uploadify-button " style="height:80%; line-height:250%; width:22%;"><span class="uploadify-button-text" for="edit_referral_source_name">Choose File</span> --%>
                                    <!-- </div> -->
                                    <div><s:file name="fileUpload" id="edit_add_attachment_form_id_fileUpload" cssClass="custom-file-input" label="Select a File to upload" size="40" />
                                    </div>
                                    <!-- <input type="file" label="Select a File to upload" class="uploadify-button"size="40"/>--></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td height="26"><span style="font-size:11px">The Upload Attachment Should Not Exceed 3MB Size.</span>
                            </td>
                        </tr>
                        <tr>
                            <td height=6></td>
                        </tr>
                        <tr>
                            <td>
                                <label class="control-label" for="edit_referral_source_name">Attachment Name</label>
                            </td>
                            <td><s:textfield cssClass="form-control" maxlength="128" style="width:99%" name="attachmentName" id="edit_attachmentName" size="20" value="%{attachmentName}" />
                            </td>
                        </tr>
                        <tr>
                            <td height=6></td>
                        </tr>
                        <tr>
                            <td>
                                <label class="control-label" for="edit_referral_source_name">Attachment Type</label>
                            </td>
                            <td>
                                <div class="controls" style="width:62%">
                                    <s:select name="chosenAttachmentType" data-rel="chosen" label="" class="required-marker" id="edit-attachmentType" headerKey="1" list="%{attachmentType}" value="%{chosenAttachmentType}"></s:select>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td height=6></td>
                        </tr>
                        <tr>
                            <td>
                                <label class="control-label" for="edit_referral_source_name">Attachment Description</label>
                            </td>
                            <td><s:textarea cssClass="form form-control autogrow" style="min-width: 382px !important; max-width:382px !important; height: 60px;" name="attachmentDescription" id="edit_attachmentDescription" value="%{attachmentDescription}" />
                            </td>
                        </tr>
                    </table>
                    <button class="btn btn-success btn-sm" title="Upload" style="margin-left:68%;margin-right: 1.5%;height:30%;margin-top:6%;margin-bottom:3%;color:white;background-color:#38976D!important;" type="submit" name="add_attachment_submit_button447" onclick="this.disabled=true;this.value='processing'" id="edit_add_attachment_submit_button"><i class="glyphicon glyphicon-upload" id="add_button_icon_id" style="padding-bottom: 12%;"></i><span id="add_button_span_id"> Upload</span>
                    </button>
                    <button class="btn btn-default" style="height:30%;margin-top:6%;margin-bottom:3%;" title="Cancel" type="button" id="edit_cancel_account_button_bottom" name="cancel_account_button_bottom" onClick="javascript:window.location='view_party?partyId=<%=partyId %>';"><i class="glyphicon glyphicon-remove" id="cancel_button_icon_id"></i><span id="cancel_button_span_id"> Cancel</span>
                    </button>
                </div>
                <div class="modal-footer"></div>
            </div>
        </s:form>
        </denter image description hereiv>
    </div>
Roman C
  • 49,761
  • 33
  • 66
  • 176
RAMYA
  • 27
  • 2
  • 4
    So... you want to view a file on a computer without downloading it on that computer? I'm sorry, but that is a logical impossibility. – TZHX Jun 08 '15 at 13:51
  • 1
    Perhabs he did not point out clearly that the app should just display the attachment and not trigger the download process to client? – Nirmi Jun 08 '15 at 13:57
  • You must [use an ` – Andrea Ligios Jun 08 '15 at 14:16
  • Yes The content in the file must be displayed with out downloading the file. – RAMYA Jun 09 '15 at 10:26

1 Answers1

0

When you see some thing in your browser it means the data is downloaded in your computer.

The browser may show it in its window (if it is html or a format which it recognize ) or it may open window which says: "I don't know this file extension, what shall I do with it, do you want to save it".

In GMail, or Dropbox they read content of file at the server, convert it to html and send the html to client. For example when you click on a PDF file the content is converted to html and jpeg or any other format which the browser KNOWS how to display it.

So user clicks on a PDF and you send him html, ( he downloads HTML ;) and of course no pop up window will ask user if he want to save it or not, because browser always display html content)

Here are some exemples which convert PDF to HTML :

Please visit: https://docs.google.com/gview?url=http://www.pdf995.com/samples/pdf.pdf&embedded=true this is google pdf viewer, which converts PDF to html. You can read more on Display PDF within web browser.

Please visit http://mozilla.github.io/pdf.js/web/viewer.html this is Mozila pdf preview which use javascript to handle the pdf preview.

You must use these kind of services, or develop your pdf, excel , doc , ... to html converters !

Community
  • 1
  • 1
Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173