Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:21:04+00:00 2026-06-09T10:21:04+00:00

Problem decription: I want to create a file upload screen using JSP. The screen

  • 0

Problem decription: I want to create a file upload screen using JSP. The screen will allow the user to select multiple files on the screen but there will be only one Upload button for all of them. On click of the upload button all the file objects should be obtained in the Action class.

But the important thing is the page should not get refreshed after submitting. There will be other information displayed on the same screen which should not get changed during the file upload is in progress.

My Attempts: I used the simple struts2 file upload feature which works fine. But it is refreshing the page on submitting.
I used AJAX (JQuery) to resolve this. The problem I am facing with AJAX is that it is not setting the File object into the file property of Action class. Hence I am not able to obtain the file object in the Action class and process further.

Can anyone please help me with this.

I am attaching the code of whatever I have tried so far.

JSP:

<s:form action="fileUpload" method="post" enctype="multipart/form-data" >
<s:file id="file" name="userImage" cssClass="fileUpload" cssStyle="fileUpload" />
<button id="px-submit">Upload</button>      
</s:form>

<script type="text/javascript">
jQuery(function($){
$('.fileUpload').fileUploader();
});
</script>

JQuery Plugin:
This is the jquery plugin that I have used.

Action Class:

public class FileUploadAction extends ActionSupport{

private File userImage;

public File getUserImage() {
    return userImage;
}

public void setUserImage(File userImage) {
    this.userImage = userImage;
}

public String execute()
{
    try
    {
        System.out.println("file name: " + userImage.toString());

    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

    return SUCCESS;
}

EDIT: Here is my struts config file.

Struts.xml

<action name="commonDataImportAction_*" class="xxx.Action">
<result name="SUCCESS" type="stream">
            <param name="contentType">text/html</param>
             <param name="inputName">inputStream</param>
        </result>

I get a nullpointer here as the file object is not getting set.

Please help.

thanks in advance.
Gaurav

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:21:05+00:00Added an answer on June 9, 2026 at 10:21 am

    I am using the same plugin and it is working fine for me. The first problem I see in your code is that you have not set the type of your upload button to submit.

    <button id="px-submit" type="submit">Upload</button>
    

    Hopefully, this should solve the null pointer excepton.
    Also, as mentioned in this plugin’s docs, you need to return a json string

    <div id='message'>success message</div>
    

    on successfull upload. So you need to change your struts.xml mapping.
    Try this and then get back to me if you face any further problems.
    EDIT:
    Ok here is my code as you requested

    JSP

    <form action="uploadImage" method="post" enctype="multipart/form-data">
       <input type="file" name="image" class="fileUpload" multiple/>
       <button id="px-submit" type="submit">Save all images</button>
       <button id="px-clear" type="reset">Clear all</button>
    </form>
    
    $('.fileUpload').fileUploader({
              autoUpload: false,
              buttonUpload: '#px-submit',
              buttonClear: '#px-clear',
    });
    

    Action class

    You need to return stream result. I am using a plugin (struts2 jquery plugin) which takes care of it vary nicely, but you dont have to use it only because of this one requirement, instead I am giving you a code to return stream result without using any plugin.(Taken from here)

    public class UploadImageAction extends ActionSupport{
            private File image;
            private String imageContentType;
            private String imageFileName;
            //getter/setter for these
            public String execute() {
             String status="";         
            try{
                  //save file code here    
             status="<div id='message'>successfully uploaded</div>"; //on success
             inputStream = new StringBufferInputStream(status);
            }catch(WhateverException e){
             status="<div id='status'>fail</div><div id='message'>Your fail message</div>"; //on error
             inputStream = new StringBufferInputStream(status);
             //other code
            }
    
            return SUCCESS;
        }
        private InputStream inputStream;
    
        public InputStream getInputStream() {
           return inputStream;
        }
    }
    

    struts.xml

    <action name="fileUpload" class="com.xxx.action.UploadImageAction">  
        <result type="stream">
          <param name="contentType">text/html</param>
          <param name="inputName">inputStream</param>
        </result>
      </action>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've problem, that i want to create a home screen widget with listview inside,
I am having a problem decrypting a file using RSA public key decryption. My
I'm using phone gap, and I want to read a file out with the
My problem is this: I want to create a grails domain instance, defining the
This is killing me! I'm using django-filebrowser, and I want to create a gallery
I want to create custom NANT files. To do this, I use C# to
I'm using PHP/MySQL to upload multiple images for photo album. The information associated with
I'm trying to create a form that will handle video file uploads from the
I have two plist files that I'm using as datasources to create NSArray and
I want to create an app that will display position on some floor plan.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.