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

  • SEARCH
  • Home
  • 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 7694949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:26:05+00:00 2026-05-31T21:26:05+00:00

I have a servlet in an GWT app thats creates a PDF file with

  • 0

I have a servlet in an GWT app thats creates a PDF file with the data given with the post request and sends the responst back:

public void service(HttpServletRequest request, HttpServletResponse response) {
        try {
            String text = request.getParameter("text");
            if (text == null || text.trim().length() == 0) {
                text = "no data";
            }

            //PDF Creation with iText
            Document document = new Document();
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, b);
            document.open();
            document.add(new Paragraph(text));
            document.close();

            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control",
                    "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");
            response.setContentType("application/pdf");

            response.setContentLength(b.size());
            OutputStream os = response.getOutputStream();
            b.writeTo(os);
            os.flush();
            os.close();

        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
    }

I want to show the created PDF to the User. I got this far on the client:

final RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,
                GWT.getModuleBaseURL() + "PdfServlet");

    rb.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuffer postData = new StringBuffer();
    postData.append(URL.encode("text")).append("=")
            .append(URL.encode(Text));

        rb.setRequestData(postData.toString());
        rb.setCallback(new RequestCallback() {

            @Override
            public void onResponseReceived(Request request,
                    Response response) {
                if (200 == response.getStatusCode()) {
                    //What to do here?
                } else {
                    //TODO:Something
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                /TODO:...

            }
        });
        try {
            rb.send();
        } catch (RequestException e) {
            e.printStackTrace();
        }

So my question is:
How do I show this PDF to the user?
All i managaged to do is show the pdf with “no data” in it..

Thank you for you 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-05-31T21:26:06+00:00Added an answer on May 31, 2026 at 9:26 pm

    Instead of using a RequestBuilder, you can simply use Window.Location.setUrl(yourDowloadUrl?key=value) and include your parameters in the query String. Note however that you must set the Content-disposition header: attachment header so the browser will prompt you to save or open the file, and not replace your GWT app.
    Better even, create a hidden iframe in your html page, and call setUrl on that widget.

    The downside of using this approach is that it doesn’t allow your client code to capture feedback if something goes wrong server-side and instead of a pdf the call returns HTML with an error string from your web server. If that’s very important to you, you should use a polling mechanism that requests the document, which is then produced and saved on the server, and checks every n seconds whether there is something to download. I have implemented something like this, which also prevents timeout issues with large documents. Let me know if you’re interested

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

Sidebar

Related Questions

I'm programming using GWT, which includes Jetty. I have defined my own servlet and
We have a gwt app that uses jcifs to pull the user name from
I have a GWT page where user enter data (start date, end date, etc.),
I have some problem with UTF-8. My client (realized in GWT) make a request
Still wresting with GWT and App Engine, and I have come to this problem:
I have a standard GWT application, and it of course uses a Java servlet
We have a GWT application which draws some resources from a separate servlet via
I have developed a simple application in GWT. After that, I generate war file
I have a simple GWT project in Eclipse, it has a servlet that calls
I have a GWT app (generated by roo) that I have decided to secure

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.