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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:01:30+00:00 2026-06-01T17:01:30+00:00

I want to download a MS Word 2003 document that I am creating with

  • 0

I want to download a MS Word 2003 document that I am creating with the content myString in it.
I have used the following code:

BufferedReader reader = new BufferedReader(new FileReader(templatePathFilename));
HttpServletResponse response = new MyHttpServletResponse();
response.setContentType ("application/msword"); 
response.setHeader ("Content-Disposition", "attachment; filename=\""+outgoingFileName); 
ServletOutputStream myOut = response.getOutputStream();
myOut.write(myString.getBytes());
myOut.flush();
myOut.close();

But the line myOut.write(myString.getBytes()) gives a NullPointerException.
MyHttpServletResponse is a class that eclipse has produced by default when I quick fix the error generated. Do I need to modify that class?
Can anyone please help!

EDIT: The actual code i am working on is as below:

BufferedReader reader = new BufferedReader(new FileReader(templatePathFilename));
String outgoingFileName = outputPathFilename;
response.setContentType("application/msword"); 
response.setHeader("Content-Disposition", "attachment; filename="+outgoingFileName);
OutputStream myOut = response.getOutputStream();
try {
String thisLine;
while ((thisLine = reader.readLine()) != null) {
    if(thisLine.contains("##"))
    {
    for (java.util.Enumeration e = FrontSheetMap.keys(); e.hasMoreElements();{
     String name = (String) e.nextElement();
     String value = FrontSheetMap.get(name).toString();
     thisLine= thisLine.replaceAll("##" + name.toUpperCase() + "##", value);
    }
   }
   myOut.write(thisLine);
   myOut.write("\n");
  }
  myOut.flush();
}catch(Exception e){}

The while loop replaces the placeholders in the input file with required values and the new content in thisLine is to be written on the output file. I need a download option which pops up on clicking the link which executes this code.

  • 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-01T17:01:31+00:00Added an answer on June 1, 2026 at 5:01 pm

    As you mentioned MyHttpServletResponse is a class that eclipse has produced by default when I quick fix the error generated, that seems to be the problem.

    Your code should be inside some servlet/JSP and the HttpServletResponse object should be taken from the container (which is passed to service/doGet/doPost methods).

    What you are using is a default/dummy implementation of HttpServletResponse which gives response.getOutputStream(); as null. If you use the container provided objects, your problem will be solved.

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

Sidebar

Related Questions

I have folders on a website I am creating that I only want logged
what I want: Download a webpage from a server > Save content in a
I want to download this picture using Ruby. How do I do that? http://farm1.static.flickr.com/92/218926700_ecedc5fef7_o.jpg
I have a possible Delphi bug (oh, damn it, I used again the word
I have an word file that contain my specified pattern text {pattern} and I
Sorry for maybe this is stupid question, I just want download source code form
I want to download a file from server to a local host. i have
I want to download the code from http://pastehtml.com/view/awono3xoq.txt , save it to a string,
I Want Add Office 2003 Primary Interop Assemblies to Visual Studio. so i following
I have a link like http://www.downloads.com/help.pdf I want to download this, and parse it

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.