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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:32:18+00:00 2026-05-16T04:32:18+00:00

I am writing a Java servlet, using Tomcat as the container, which creates and

  • 0

I am writing a Java servlet, using Tomcat as the container, which creates and serves PDF files to the end-user. Currently the PDF files are created in-memory and written out as a response to a POST.

I would like to change this up somewhat so that the PDF files are written to disk (so they can be served up again later). I am having trouble locating a suitable “how-to” for doing this.

How can I configure my servlet to write to and read files from a directory server-side? From what I’ve read, I think I need to locate this directory somewhere outside where my “exploded webapp” lives in $CATALINA_BASE for security reasons, and I need to use a Context or somesuch.

  • 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-16T04:32:19+00:00Added an answer on May 16, 2026 at 4:32 am

    You can just use the usual FileOutputStream and FileInputStream classes to respectively write to and read from the disk. Change your PDF generator to write to FileOutputStream and change your file servlet to read from FileInputStream.

    And, indeed, you’d like to store those files outside the webapp, else it will all get lost whenever you redeploy the webapp. You don’t need the ServletContext, it’s only useful to convert a relative web path to an absolute disk file system path. You don’t need it when you’re storing it outside the webapp, you namely already know the absolute disk file system path.

    See also

    • Java IO tutorial
    • Basic example of FileServlet
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Java desktop client which will send multiple files over the wire
Hi I am currently writing a servlet using Apache XML-RPC connecting to OpenERP. There
I'm writing a Java servlet that I'm planning to deploy on Amazon AWS using
I'm writing my first Java EE application, using EJBs, Servlet, JSPs and the likes.
I am writing java/spring webapp in which every user can have its own word
I'm writing a Java servlet in Eclipse (to be hosted on Google App Engine)
I'm writing HTML code for a Java servlet. I first write the code in
I am writing java code. which will work on windows and linux. some code
I am currently writing a Java compiler and have implemented section 15.12.2.7. of the
Good evening, I am in the process of writing a Java Servlet (Struts 2,

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.