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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:14:53+00:00 2026-06-08T22:14:53+00:00

I have my ExportServlet, which are generating XLSX files (Excel) which my user will

  • 0

I have my ExportServlet, which are generating XLSX files (Excel) which my user will request from my GWT application by clicking a export button.

If I use the GET approach, the user are prompted to download the file. The code looks like this:

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
{
    try
    {
        byte[] xlsx = createTest("");
        sendXLSX(resp, xlsx, "test.xlsx");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
 }

void sendXLSX(HttpServletResponse response, byte[] bytes, String name)
        throws IOException
{
    ServletOutputStream stream = null;

    stream = response.getOutputStream();
    response.setContentType(CONTENT_TYPE_XLSX);
    response.addHeader("Content-Type", CONTENT_TYPE_XLSX);
    response.addHeader("Content-Disposition", "inline; filename=" + name);
    response.setContentLength((int) bytes.length);
    stream.write(bytes);
    stream.close();
}

This is invoked by the GWT client in the following manner:

String url = GWT.getModuleBaseURL() + "ExportServlet";
Window.open(url, "", "");

and the user is prompted to download the file. Good, thats what I want 🙂

But I would like to attach a lot of data in the request, and afaik, there is a limit to how much data you can put in a URL parameter (“ExportServlet?data=…”), so I would like to wrap that in a POST request instead.

I have tried the following from GWT:

String url = GWT.getModuleBaseURL() + "ExportServlet";
RequestBuilder builder = new RequestBuilder(
                            RequestBuilder.POST, url);
Request response = builder.sendRequest("test data", new RequestCallback() 
{
    @Override
    public void onResponseReceived(Request request, Response response)
    {
        System.out.println("");
    }

    @Override
    public void onError(Request request, Throwable exception)
    {
        System.out.println("");
    }
});

and this in my servlet:

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
{
    try
    {
        String data = req.getReader().readLine();
        byte[] xlsx = createTest(data);
        sendXLSX(resp, xlsx, "test.xlsx");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

but the user is not prompted to download the file. The doPost method is invoked and the data is received by the servlet, but am I supposed to extract the XLSX file from the response which I receive in the GWT app? and how am I suppose to do that?

Appreciate any help or comments 🙂

  • 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-08T22:14:54+00:00Added an answer on June 8, 2026 at 10:14 pm

    Ok, so I went with the 3rd approach in the linked SO question.

    Create a FormPanel, put your data in hidden fields, set the URL to your servlet, call the submit method programmatically on the form and the described problem in this SO question will be solved.

    Details on how to extract data from the hidden fields:

    So my doPost looks similar to this:

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) { 
        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iterator = upload.getItemIterator(req);
    
        while (iterator.hasNext()) {
            FileItemStream item = iterator.next();
            if (item.isFormField()) {
                String name = item.getFieldName();
                if (name.equalsIgnoreCase("fieldName")) {
                    data = Streams.asString(item.openStream(), ENCODING_UTF8);
                }
            }
        }
        ...
    

    I have a hidden field in my form with the name “fieldName”, where the data is put and submitted to the servlet. Hope this helps 🙂

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

Sidebar

Related Questions

Have a bunch of classes which I need to do serialize and deserialize from/to
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
have a nice day. I got problem when trying to create an image from
Have converted devise new session from erb to Haml but doens't work, this is
Have one Doubt In MVC Architecture we can able to pass data from Controller
Have data that has this kind of structure. Will be in ascending order by
Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
have a help file which i have created in Notepad++ with the following syntax

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.