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 8443811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:14:22+00:00 2026-06-10T09:14:22+00:00

i want to send a file from client to server. My code: Client side

  • 0

i want to send a file from client to server.

My code:

Client side:

private FormPanel getFormPanel() {
    if (formPanel == null) {
        formPanel = new FormPanel();
    formPanel.setMethod(FormPanel.METHOD_POST);
        formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
        formPanel.setAction(GWT.getHostPageBaseURL() +"UploadFileServlet");
        formPanel.setWidget(getFlexTable_1());

                System.out.println(GWT.getHostPageBaseURL() +"UploadFileServlet");
    }
    return formPanel;
}

In getFlexTable_1()

flexTable.setWidget(1, 1, getFileUpload());

In getFileUpload()

private FileUpload getFileUpload() {
    if (fileUpload == null) {
        fileUpload = new FileUpload();
        fileUpload.setName("upload");
    }
    return fileUpload;
}

private Button getAddButton() {
        if (addButton == null) {
            addButton = new Button("ADD");
            addButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                               formPanel.submit();
        }
        });
    }
return addButton;

}

On server side

public class CmisFileUpload extends HttpServlet implements Servlet{

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        byte[] buffer = new byte[115200];//
        String fileName = null;
        String mimetype = null;
        String majorVersion = null;
        InputStream stream = null;
        System.out.println("ServletWorking Fine");
}

Now when i Choose a file and click on ADD button i cant see the output on server side for this code System.out.println("ServletWorking Fine");

The outPut of System.out.println(GWT.getHostPageBaseURL() +"UploadFileServlet"); on client side is

http://127.0.0.1:8888/UploadFileServlet

and when i use this url directly on browser i get server side output for System.out.println("ServletWorking Fine");**


Edited

I created one more web application for file upload

public class Uploadfile implements EntryPoint {

    FormPanel uploadForm = new FormPanel();
    public void onModuleLoad() {

        HorizontalPanel horizontalPanel = new HorizontalPanel();

      uploadForm.setAction(GWT.getHostPageBaseURL() +"UploadFileServlet"); 

        uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART); 
        uploadForm.setMethod(FormPanel.METHOD_POST); 
        horizontalPanel.add(uploadForm);

        // Create a panel to hold all of the form widgets. 
        VerticalPanel panel = new VerticalPanel(); 
        uploadForm.setWidget(panel); 

        FlexTable flexTable = new FlexTable();
        panel.add(flexTable);

        // Create a FileUpload widget. 
        FileUpload upload = new FileUpload(); 
        upload.setName("uploadFormElement"); 
        flexTable.setWidget(2, 3, upload);
        // panel.add(upload); 

        // Add a 'submit' button. 
        Button uploadSubmitButton = new Button("Submit"); 
        panel.add(uploadSubmitButton); 

        uploadSubmitButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                // TODO Auto-generated method stub
                 uploadForm.submit(); 
            }
        });
        uploadForm.addFormHandler(new FormHandler() { 
          public void onSubmit(FormSubmitEvent event) { 
          } 
          public void onSubmitComplete(FormSubmitCompleteEvent event) { 
            Window.alert(event.getResults()); 
          } 
        }); 
        RootPanel.get().add(horizontalPanel); 
    }
}

Server

protected void doGet(HttpServletRequest request, 
            HttpServletResponse response) 
                            throws ServletException, IOException { 
      doPost(request, response);
  }

  protected void doPost(HttpServletRequest request, 
            HttpServletResponse response) 
                            throws ServletException, IOException { 

      System.out.println("working fine" );
   }

This code is working fine

According to me there is no difference between the codes.

Plz tell me why the formpanel.submit is not working properly.

Plz help.

  • 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-10T09:14:24+00:00Added an answer on June 10, 2026 at 9:14 am

    Is hide() method is closing the window??? If Yes then

    remove move code hide(); after formPanel.submit();

    for hide() use FormHandler. for eg

    uploadForm.addFormHandler(new FormHandler() {
    
        public void onSubmitComplete(FormSubmitCompleteEvent event) {
            hide();
        }
    
        public void onSubmit(FormSubmitEvent event) {
    
        }
    
    });
    

    reason: The FormPanel must not be detached (i.e. removed from its parent until the submission is complete. Otherwise, notification of submission will fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send more than one image file from client to server for
I want to ask, why I cannot transfer file from server to client? When
In C# I've to write code for Docx file send from server application to
How can i send image from the client side to server? i have a
I want to send a video file from a server written in java to
I have a client application, and a server one. I want to send a
I am new to raw socket. I want write a server and a client
my client program first connects to server,then server send a file and then client
Hi I want to send a fixed amount of data (say 5MB) from server
I need to send a file to webdav server from iphone app, it's include

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.