1

I am trying to implement this plugin in struts 2 app. I am able to get the file to server, but when i respond from action with proper div, i get an empty page with current year as only content. In IE i get:

Message: Permission denied
Line: 4
Char: 2462
Code: 0
URI: https://blah.blee.blah.ca/js/jquery/js/jquery-1.7.2.min.js 

When ever i refresh the page (the page that shows 2012 i click back first) and then reload the page, i see that the file is on the server.

Here is my JSP fragment

<div id="main_container">
   <form action="uploadFile" method="post" enctype="multipart/form-data">
        <input type="file" name="pdffile" class="fileUpload" multiple />
        <button id="px-submit" type="submit">Save</button>
        <button id="px-clear" type="reset">Clear</button>
   </form>
   <script type="text/javascript">
        jQuery(function($) {
            $('.fileUpload').fileUploader({
                limit : 1,
                autoUpload : false,
                selectFileLabel : 'Select',
                buttonUpload : '#px-submit',
                buttonClear : '#px-clear',
                allowedExtension : 'pdf'
            });
        });
    </script>
</div>

struts 2 action:

public String uploadFile() {

        String result = Action.ERROR;

        String status = null;

        if (log.isDebugEnabled()) {
            log.debug("doUpload()");
        }

        try {
            showAttachmentDiv = true;
            if (log.isDebugEnabled()) {
                log.debug("doUpload() with filename: '" + this.filename
                        + "' and contentType '" + this.contentType + "'");
                if (uploadedFile != null) {
                    log.debug("doUplaod() with file.getAbsolutePath(): "
                            + uploadedFile.getAbsolutePath());
                } else {
                    log.debug("doUplaod() with file: null ");
                }
            }

            if (uploadedFile != null) {

                if (this.getActionErrors().size() == 0) {
                    AttachmentsUIObject attachment = new AttachmentsUIObject();
                    // the file object is eventually deleted by the fileUpload
                    // utility, so we just copy it.
                    File copiedFile = copyFile(uploadedFile);
                    attachment.setFile(copiedFile);
                    attachment.setType(this.uploadAttachmentType);
                    attachment.setOriginalFilename(this.filename);

                    attachmentsList.add(attachment);

                    // save file code here
                    status = getText(DIV_MESSAGE_UPLOAD_SUCCESS); // on
                                                                    // success
                    // inputStream = new StringBufferInputStream(status);

                } else {
                    uploadedFile.delete();

                    status = getText(DIV_MESSAGE_UPLOAD_FAIL,
                            new String[] { getActionErrors().toString() });

                }

                result = Action.SUCCESS;
            } else {
                addActionError(getText("validation.file.missing"));
                result = Action.INPUT;
            }



        } catch (Exception e) {
            log.error("doUpload()", e);
            addActionError(getText("error.uploadfailed"));

            status = getText(DIV_MESSAGE_UPLOAD_FAIL,
                    new String[] { getText("error.uploadfailed") }); // on

            result = BaseAction.ERROR_UPLOAD;
        }

        inputStream = new StringBufferInputStream(status);

        return result;
    }

struts 2 xml config:

<action name="uploadFile" method="uploadFile" class="xxx.SubmitAction">
     <result name="success" type="stream">
           <param name="contentType">text/html</param>
           <param name="inputName">inputStream</param>
     </result>
</action>

One important note. There is oracle web center. This struts 2 application is accessed from portal. Could this be something related to that?

jquery-load-throws-permission-denied-error-in-ie

Community
  • 1
  • 1
Emil Iakoupov
  • 189
  • 14
  • The name of your file element is `pdffile` but I cant see that variable used in your action class. However, you are using `uploadedFile` variable as the uploaded file which is the name of the form.I am using the same plugin in my project and according to its documentation, you should first try to make your action class work without implementing this plugin. Implement it only after the normal file upload process(with page reload) is working fine – Anupam Oct 26 '12 at 20:05
  • This class used the struts 2 file upload before. The file does end up on the server. the getters and setters for pdffile are `getPdffile` and `setPdffile`. In the environment there is a portal in front with ist own js and css libraries. Do you return response from action same way as i am trying? – Emil Iakoupov Oct 26 '12 at 20:16
  • yes I am setting the `inputStream` variable with `
    success
    Successfully uploaded
    `
    – Anupam Oct 27 '12 at 04:59
  • I tried another plugin ,which required a JSON array in response. I tried JSON here as well but i get the same result. – Emil Iakoupov Oct 27 '12 at 17:32
  • Then something is wrong in your setup. I still dont understand what is `AttachmentsUIObject` object and how are you mapping HTML `File` field to your action class variable – Anupam Oct 28 '12 at 03:48

0 Answers0