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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:59:25+00:00 2026-05-24T08:59:25+00:00

I have a use case where I need to return a PDF to a

  • 0

I have a use case where I need to return a PDF to a user which is generated for us. It seems that what I need to do is utilize the ResponseEntity in this case, but I have a couple of things which are not very clear.

  1. How can I redirect the user — let’s pretend they don’t have the permissions to access this page? How can I redirect them to a separate controller?
  2. Am I able to set the response encoding?
  3. Can I achieve either of these two without bringing in the HttpResponse as a parameter to my RequestMapping?

I’m using Spring 3.0.5. Example code below:

@Controller
@RequestMapping("/generate/data/pdf.xhtml")
public class PdfController {

    @RequestMapping
    public ResponseEntity<byte []> generatePdf(@RequestAttribute("key") Key itemKey) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.valueOf("application/pdf"));

        if (itemKey == null || !allowedToViewPdf(itemKey)) {
            //How can I redirect here?
        }

        //How can I set the response content type to UTF_8 -- I need this
        //for a separate controller
        return new ResponseEntity<byte []>(PdfGenerator.generateFromKey(itemKey),
                                           responseHeaders,
                                           HttpStatus.CREATED);
    }

I’d really like to not pull in the Response… None of my controllers have done so thus far, and I’d hate to have to bring it in at all.

  • 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-24T08:59:26+00:00Added an answer on May 24, 2026 at 8:59 am

    Instead of dealing with redirecting (these are instances which we open in new windows / tabs) anyhow we decided to just display the error message they would have received.

    This likely won’t work for all, but with the way we add error / status messages we were unable to get those messages to persist on the view upon exception occurring.

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

Sidebar

Related Questions

Have a use case wherein need to maintain a connection open to a database
I have the following use case , lot of code which was tightly coupled
I have a small but significant query. I'll give a similiar use case but
That is, I'd like to have a tuple of values. The use case on
I want to use a case statement in my user-defined functions because I need
In C# I have a use case where I have a mapping from int
I'm looking for a good reader/writer lock in C++. We have a use case
I have the following use case, a struct with some boolean and int variables
My use case is very simple : I have a GUI application, and inside
Does anyone use have a good regex library that they like to use? Most

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.